@@ -177,10 +177,10 @@ |
||
| 177 | 177 | * </pre> |
| 178 | 178 | * |
| 179 | 179 | * @param [type] $field_options [description] |
| 180 | - * @param [type] $template_id [description] |
|
| 181 | - * @param [type] $field_id [description] |
|
| 182 | - * @param [type] $context [description] |
|
| 183 | - * @param [type] $input_type [description] |
|
| 180 | + * @param string $template_id [description] |
|
| 181 | + * @param string $field_id [description] |
|
| 182 | + * @param string $context [description] |
|
| 183 | + * @param string $input_type [description] |
|
| 184 | 184 | * @return [type] [description] |
| 185 | 185 | */ |
| 186 | 186 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @type array |
| 71 | 71 | * @since 1.15.2 |
| 72 | 72 | */ |
| 73 | - var $contexts = array( 'single', 'multiple', 'edit', 'export' ); |
|
| 73 | + var $contexts = array('single', 'multiple', 'edit', 'export'); |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * @internal Not yet implemented |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | function __construct() { |
| 95 | 95 | |
| 96 | 96 | // Modify the field options based on the name of the field type |
| 97 | - add_filter( sprintf( 'gravityview_template_%s_options', $this->name ), array( &$this, 'field_options' ), 10, 5 ); |
|
| 97 | + add_filter(sprintf('gravityview_template_%s_options', $this->name), array(&$this, 'field_options'), 10, 5); |
|
| 98 | 98 | |
| 99 | 99 | } |
| 100 | 100 | |
@@ -102,35 +102,35 @@ discard block |
||
| 102 | 102 | $options = array( |
| 103 | 103 | 'link_to_post' => array( |
| 104 | 104 | 'type' => 'checkbox', |
| 105 | - 'label' => __( 'Link to the post', 'gravityview' ), |
|
| 106 | - 'desc' => __( 'Link to the post created by the entry.', 'gravityview' ), |
|
| 105 | + 'label' => __('Link to the post', 'gravityview'), |
|
| 106 | + 'desc' => __('Link to the post created by the entry.', 'gravityview'), |
|
| 107 | 107 | 'value' => false, |
| 108 | 108 | ), |
| 109 | 109 | 'link_to_term' => array( |
| 110 | 110 | 'type' => 'checkbox', |
| 111 | - 'label' => __( 'Link to the category or tag', 'gravityview' ), |
|
| 112 | - 'desc' => __( 'Link to the current category or tag. "Link to single entry" must be unchecked.', 'gravityview' ), |
|
| 111 | + 'label' => __('Link to the category or tag', 'gravityview'), |
|
| 112 | + 'desc' => __('Link to the current category or tag. "Link to single entry" must be unchecked.', 'gravityview'), |
|
| 113 | 113 | 'value' => false, |
| 114 | 114 | ), |
| 115 | 115 | 'dynamic_data' => array( |
| 116 | 116 | 'type' => 'checkbox', |
| 117 | - 'label' => __( 'Use the live post data', 'gravityview' ), |
|
| 118 | - 'desc' => __( 'Instead of using the entry data, instead use the current post data.', 'gravityview' ), |
|
| 117 | + 'label' => __('Use the live post data', 'gravityview'), |
|
| 118 | + 'desc' => __('Instead of using the entry data, instead use the current post data.', 'gravityview'), |
|
| 119 | 119 | 'value' => true, |
| 120 | 120 | ), |
| 121 | 121 | 'date_display' => array( |
| 122 | 122 | 'type' => 'text', |
| 123 | - 'label' => __( 'Override Date Format', 'gravityview' ), |
|
| 124 | - 'desc' => sprintf( __( 'Define how the date is displayed (using %sthe PHP date format%s)', 'gravityview'), '<a href="https://codex.wordpress.org/Formatting_Date_and_Time">', '</a>' ), |
|
| 123 | + 'label' => __('Override Date Format', 'gravityview'), |
|
| 124 | + 'desc' => sprintf(__('Define how the date is displayed (using %sthe PHP date format%s)', 'gravityview'), '<a href="https://codex.wordpress.org/Formatting_Date_and_Time">', '</a>'), |
|
| 125 | 125 | /** |
| 126 | 126 | * @filter `gravityview_date_format` Override the date format with a [PHP date format](https://codex.wordpress.org/Formatting_Date_and_Time) |
| 127 | 127 | * @param[in,out] null|string $date_format Date Format (default: null) |
| 128 | 128 | */ |
| 129 | - 'value' => apply_filters( 'gravityview_date_format', null ) |
|
| 129 | + 'value' => apply_filters('gravityview_date_format', null) |
|
| 130 | 130 | ), |
| 131 | 131 | 'new_window' => array( |
| 132 | 132 | 'type' => 'checkbox', |
| 133 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 133 | + 'label' => __('Open link in a new tab or window?', 'gravityview'), |
|
| 134 | 134 | 'value' => false, |
| 135 | 135 | ), |
| 136 | 136 | ); |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | * @filter `gravityview_field_support_options` Modify the settings that a field supports |
| 140 | 140 | * @param array $options Options multidimensional array with each key being the input name, with each array setting having `type`, `label`, `desc` and `value` (default values) keys |
| 141 | 141 | */ |
| 142 | - return apply_filters( 'gravityview_field_support_options', $options ); |
|
| 142 | + return apply_filters('gravityview_field_support_options', $options); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - function add_field_support( $key = '', &$field_options ) { |
|
| 145 | + function add_field_support($key = '', &$field_options) { |
|
| 146 | 146 | |
| 147 | 147 | $options = $this->field_support_options(); |
| 148 | 148 | |
| 149 | - if( isset( $options[ $key ] ) ) { |
|
| 150 | - $field_options[ $key ] = $options[ $key ]; |
|
| 149 | + if (isset($options[$key])) { |
|
| 150 | + $field_options[$key] = $options[$key]; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | return $field_options; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param [type] $input_type [description] |
| 184 | 184 | * @return [type] [description] |
| 185 | 185 | */ |
| 186 | - function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 186 | + function field_options($field_options, $template_id, $field_id, $context, $input_type) { |
|
| 187 | 187 | |
| 188 | 188 | $this->_field_options = $field_options; |
| 189 | 189 | $this->_field_id = $field_id; |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @param GF_Field_List $field Gravity Forms field |
| 27 | 27 | * @param string|array $field_value Serialized or unserialized array value for the field |
| 28 | - * @param int|string $column_id The numeric key of the column (0-index) or the label of the column |
|
| 28 | + * @param integer $column_id The numeric key of the column (0-index) or the label of the column |
|
| 29 | 29 | * @param string $format If set to 'raw', return an array of values for the column. Otherwise, allow Gravity Forms to render using `html` or `text` |
| 30 | 30 | * |
| 31 | 31 | * @return array|string|null Returns null if the $field_value passed wasn't an array or serialized array |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | parent::__construct(); |
| 15 | 15 | |
| 16 | - add_filter( 'gravityview/template/field_label', array( $this, '_filter_field_label' ), 10, 4 ); |
|
| 16 | + add_filter('gravityview/template/field_label', array($this, '_filter_field_label'), 10, 4); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -30,24 +30,24 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return array|string|null Returns null if the $field_value passed wasn't an array or serialized array |
| 32 | 32 | */ |
| 33 | - public static function column_value( GF_Field_List $field, $field_value, $column_id = 0, $format = 'html' ) { |
|
| 33 | + public static function column_value(GF_Field_List $field, $field_value, $column_id = 0, $format = 'html') { |
|
| 34 | 34 | |
| 35 | - $list_rows = maybe_unserialize( $field_value ); |
|
| 35 | + $list_rows = maybe_unserialize($field_value); |
|
| 36 | 36 | |
| 37 | - if( ! is_array( $list_rows ) ) { |
|
| 38 | - do_action( 'gravityview_log_error', __METHOD__ . ' - $field_value did not unserialize', $field_value ); |
|
| 37 | + if (!is_array($list_rows)) { |
|
| 38 | + do_action('gravityview_log_error', __METHOD__.' - $field_value did not unserialize', $field_value); |
|
| 39 | 39 | return null; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $column_values = array(); |
| 43 | 43 | |
| 44 | 44 | // Each list row |
| 45 | - foreach ( $list_rows as $list_row ) { |
|
| 45 | + foreach ($list_rows as $list_row) { |
|
| 46 | 46 | $current_column = 0; |
| 47 | - foreach ( $list_row as $column_key => $column_value ) { |
|
| 47 | + foreach ($list_row as $column_key => $column_value) { |
|
| 48 | 48 | |
| 49 | 49 | // If the label of the column matches $column_id, or the numeric key value matches, add the value |
| 50 | - if( (string)$column_key === (string)$column_id || ( is_numeric( $column_id ) && (int)$column_id === $current_column ) ) { |
|
| 50 | + if ((string)$column_key === (string)$column_id || (is_numeric($column_id) && (int)$column_id === $current_column)) { |
|
| 51 | 51 | $column_values[] = $column_value; |
| 52 | 52 | } |
| 53 | 53 | $current_column++; |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | // Return the array of values |
| 58 | - if( 'raw' === $format ) { |
|
| 58 | + if ('raw' === $format) { |
|
| 59 | 59 | return $column_values; |
| 60 | 60 | } |
| 61 | 61 | // Return the Gravity Forms Field output |
| 62 | 62 | else { |
| 63 | - return $field->get_value_entry_detail( serialize( $column_values ), '', false, $format ); |
|
| 63 | + return $field->get_value_entry_detail(serialize($column_values), '', false, $format); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -76,30 +76,30 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return string Existing label if the field isn't |
| 78 | 78 | */ |
| 79 | - public function _filter_field_label( $label, $field, $form, $entry ) { |
|
| 79 | + public function _filter_field_label($label, $field, $form, $entry) { |
|
| 80 | 80 | |
| 81 | - $field_object = RGFormsModel::get_field( $form, $field['id'] ); |
|
| 81 | + $field_object = RGFormsModel::get_field($form, $field['id']); |
|
| 82 | 82 | |
| 83 | 83 | // Not a list field |
| 84 | - if( ! $field_object || 'list' !== $field_object->type ) { |
|
| 84 | + if (!$field_object || 'list' !== $field_object->type) { |
|
| 85 | 85 | return $label; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Custom label is defined, so use it |
| 89 | - if( ! empty( $field['custom_label'] ) ) { |
|
| 89 | + if (!empty($field['custom_label'])) { |
|
| 90 | 90 | return $label; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $field_id_array = explode( '.', $field['id'] ); |
|
| 93 | + $field_id_array = explode('.', $field['id']); |
|
| 94 | 94 | |
| 95 | 95 | // Parent field, not column field |
| 96 | - if( ! isset( $field_id_array[1] ) ) { |
|
| 96 | + if (!isset($field_id_array[1])) { |
|
| 97 | 97 | return $label; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $column_id = intval( $field_id_array[1] ); |
|
| 100 | + $column_id = intval($field_id_array[1]); |
|
| 101 | 101 | |
| 102 | - return self::get_column_label( $field_object, $column_id, $label ); |
|
| 102 | + return self::get_column_label($field_object, $column_id, $label); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - public static function get_column_label( GF_Field_List $field, $column_id, $backup_label = '' ) { |
|
| 116 | + public static function get_column_label(GF_Field_List $field, $column_id, $backup_label = '') { |
|
| 117 | 117 | |
| 118 | 118 | // Doesn't have columns enabled |
| 119 | - if( ! isset( $field->choices ) || ! $field->enableColumns ) { |
|
| 119 | + if (!isset($field->choices) || !$field->enableColumns) { |
|
| 120 | 120 | return $backup_label; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // Get the list of columns, with numeric index keys |
| 124 | - $columns = wp_list_pluck( $field->choices, 'text' ); |
|
| 124 | + $columns = wp_list_pluck($field->choices, 'text'); |
|
| 125 | 125 | |
| 126 | - return isset( $columns[ $column_id ] ) ? $columns[ $column_id ] : $backup_label; |
|
| 126 | + return isset($columns[$column_id]) ? $columns[$column_id] : $backup_label; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * We could do this in a cleaner fashion, but this prevents a lot of code duplication, checking for URL structure, etc. |
| 30 | 30 | * |
| 31 | - * @param int|WP_Post $id Optional. Post ID or post object. Default current post. |
|
| 31 | + * @param integer $id Optional. Post ID or post object. Default current post. |
|
| 32 | 32 | * |
| 33 | 33 | * @return array URL args, if exists. Empty array if not. |
| 34 | 34 | */ |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @since 1.15 Added $object param |
| 102 | 102 | * |
| 103 | 103 | * @param string $file_path Full path to a file |
| 104 | - * @param mixed $object Pass pseudo-global to the included file |
|
| 104 | + * @param GravityView_Edit_Entry_Render $object Pass pseudo-global to the included file |
|
| 105 | 105 | * @return string Included file contents |
| 106 | 106 | */ |
| 107 | 107 | function gravityview_ob_include( $file_path, $object = NULL ) { |
@@ -276,7 +276,6 @@ discard block |
||
| 276 | 276 | * Do a _very_ basic match for second-level TLD domains, like `.co.uk` |
| 277 | 277 | * |
| 278 | 278 | * Ideally, we'd use https://github.com/jeremykendall/php-domain-parser to check for this, but it's too much work for such a basic functionality. Maybe if it's needed more in the future. So instead, we use [Basic matching regex](http://stackoverflow.com/a/12372310). |
| 279 | - * @param string $domain Domain to check if it's a TLD or subdomain |
|
| 280 | 279 | * @return string Extracted domain if it has a subdomain |
| 281 | 280 | */ |
| 282 | 281 | function _gravityview_strip_subdomain( $string_maybe_has_subdomain ) { |
@@ -296,7 +295,7 @@ discard block |
||
| 296 | 295 | * Checks whether `false`, `null`, empty string, empty array, object with no vars defined |
| 297 | 296 | * |
| 298 | 297 | * @since 1.15.1 |
| 299 | - * @param mixed $value Check whether this is empty |
|
| 298 | + * @param string $value Check whether this is empty |
|
| 300 | 299 | * @param boolean $zero_is_empty Should the number zero be treated as an empty value? |
| 301 | 300 | * @param boolean $allow_string_booleans Whether to check if 'yes', 'true' => `true` and 'no', 'false' => `false` |
| 302 | 301 | * @return boolean True: empty; false: not empty |
@@ -307,7 +307,7 @@ |
||
| 307 | 307 | ! isset( $value ) // If it's not set, it's empty! |
| 308 | 308 | || false === $value |
| 309 | 309 | || null === $value |
| 310 | - || '' === $value // Empty string |
|
| 310 | + || '' === $value // Empty string |
|
| 311 | 311 | || array() === $value // Empty array |
| 312 | 312 | || ( is_object( $value ) && ! get_object_vars( $value ) ) // Empty object |
| 313 | 313 | ) { |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return bool true: $mixed is *not* an empty string; false: $mixed *is* an empty string |
| 17 | 17 | */ |
| 18 | -function gravityview_is_not_empty_string( $mixed = '' ) { |
|
| 19 | - return ( $mixed !== '' ); |
|
| 18 | +function gravityview_is_not_empty_string($mixed = '') { |
|
| 19 | + return ($mixed !== ''); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return array URL args, if exists. Empty array if not. |
| 34 | 34 | */ |
| 35 | -function gravityview_get_permalink_query_args( $id = 0 ) { |
|
| 35 | +function gravityview_get_permalink_query_args($id = 0) { |
|
| 36 | 36 | |
| 37 | - $parsed_permalink = parse_url( get_permalink( $id ) ); |
|
| 37 | + $parsed_permalink = parse_url(get_permalink($id)); |
|
| 38 | 38 | |
| 39 | - $permalink_args = isset( $parsed_permalink['query'] ) ? $parsed_permalink['query'] : false; |
|
| 39 | + $permalink_args = isset($parsed_permalink['query']) ? $parsed_permalink['query'] : false; |
|
| 40 | 40 | |
| 41 | - if( empty( $permalink_args ) ) { |
|
| 41 | + if (empty($permalink_args)) { |
|
| 42 | 42 | return array(); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - parse_str( $permalink_args, $args ); |
|
| 45 | + parse_str($permalink_args, $args); |
|
| 46 | 46 | |
| 47 | 47 | return $args; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -if( ! function_exists( 'gravityview_sanitize_html_class' ) ) { |
|
| 50 | +if (!function_exists('gravityview_sanitize_html_class')) { |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * sanitize_html_class doesn't handle spaces (multiple classes). We remedy that. |
@@ -58,20 +58,20 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return string Sanitized CSS string |
| 60 | 60 | */ |
| 61 | - function gravityview_sanitize_html_class( $classes ) { |
|
| 61 | + function gravityview_sanitize_html_class($classes) { |
|
| 62 | 62 | |
| 63 | - if ( is_string( $classes ) ) { |
|
| 64 | - $classes = explode( ' ', $classes ); |
|
| 63 | + if (is_string($classes)) { |
|
| 64 | + $classes = explode(' ', $classes); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // If someone passes something not string or array, we get outta here. |
| 68 | - if ( ! is_array( $classes ) ) { |
|
| 68 | + if (!is_array($classes)) { |
|
| 69 | 69 | return $classes; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $classes = array_map( 'sanitize_html_class', $classes ); |
|
| 72 | + $classes = array_map('sanitize_html_class', $classes); |
|
| 73 | 73 | |
| 74 | - return implode( ' ', $classes ); |
|
| 74 | + return implode(' ', $classes); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return string Stripped string! |
| 91 | 91 | */ |
| 92 | -function gravityview_strip_whitespace( $string ) { |
|
| 93 | - $string = normalize_whitespace( $string ); |
|
| 94 | - return preg_replace('/[\r\n\t ]+/', ' ', $string ); |
|
| 92 | +function gravityview_strip_whitespace($string) { |
|
| 93 | + $string = normalize_whitespace($string); |
|
| 94 | + return preg_replace('/[\r\n\t ]+/', ' ', $string); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | * @param mixed $object Pass pseudo-global to the included file |
| 105 | 105 | * @return string Included file contents |
| 106 | 106 | */ |
| 107 | -function gravityview_ob_include( $file_path, $object = NULL ) { |
|
| 108 | - if( ! file_exists( $file_path ) ) { |
|
| 109 | - do_action( 'gravityview_log_error', __FUNCTION__ . ': File path does not exist. ', $file_path ); |
|
| 107 | +function gravityview_ob_include($file_path, $object = NULL) { |
|
| 108 | + if (!file_exists($file_path)) { |
|
| 109 | + do_action('gravityview_log_error', __FUNCTION__.': File path does not exist. ', $file_path); |
|
| 110 | 110 | return ''; |
| 111 | 111 | } |
| 112 | 112 | ob_start(); |
| 113 | - include( $file_path ); |
|
| 113 | + include($file_path); |
|
| 114 | 114 | return ob_get_clean(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | function gravityview_get_floaty() { |
| 123 | 123 | |
| 124 | - if( function_exists('is_rtl') && is_rtl() ) { |
|
| 124 | + if (function_exists('is_rtl') && is_rtl()) { |
|
| 125 | 125 | $style = 'margin:10px 10px 10px 0;'; |
| 126 | 126 | $class = 'alignright'; |
| 127 | 127 | } else { |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $class = 'alignleft'; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - return '<img src="'.plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ).'" class="'.$class.'" height="87" width="66" alt="The GravityView Astronaut Says:" style="'.$style.'" />'; |
|
| 132 | + return '<img src="'.plugins_url('assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE).'" class="'.$class.'" height="87" width="66" alt="The GravityView Astronaut Says:" style="'.$style.'" />'; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @return string Converted number in string format. |
| 151 | 151 | */ |
| 152 | -function gravityview_number_format( $number, $decimals = '' ) { |
|
| 152 | +function gravityview_number_format($number, $decimals = '') { |
|
| 153 | 153 | global $wp_locale; |
| 154 | 154 | |
| 155 | - if( '' === $decimals ) { |
|
| 155 | + if ('' === $decimals) { |
|
| 156 | 156 | |
| 157 | - $decimal_point = isset( $wp_locale ) ? $wp_locale->number_format['decimal_point'] : '.'; |
|
| 157 | + $decimal_point = isset($wp_locale) ? $wp_locale->number_format['decimal_point'] : '.'; |
|
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * Calculate the position of the decimal point in the number |
| 161 | 161 | * @see http://stackoverflow.com/a/2430144/480856 |
| 162 | 162 | */ |
| 163 | - $decimals = strlen( substr( strrchr( $number, $decimal_point ), 1 ) ); |
|
| 163 | + $decimals = strlen(substr(strrchr($number, $decimal_point), 1)); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $number = number_format_i18n( $number, (int)$decimals ); |
|
| 166 | + $number = number_format_i18n($number, (int)$decimals); |
|
| 167 | 167 | |
| 168 | 168 | return $number; |
| 169 | 169 | } |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | * @param string $value Existing URL |
| 178 | 178 | * @return string If parse_url doesn't find a 'host', returns original value. Otherwise, returns formatted link. |
| 179 | 179 | */ |
| 180 | -function gravityview_format_link( $value = null ) { |
|
| 180 | +function gravityview_format_link($value = null) { |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | - $parts = parse_url( $value ); |
|
| 183 | + $parts = parse_url($value); |
|
| 184 | 184 | |
| 185 | 185 | // No domain? Strange...show the original text. |
| 186 | - if( empty( $parts['host'] ) ) { |
|
| 186 | + if (empty($parts['host'])) { |
|
| 187 | 187 | return $value; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | * @param boolean $enable Whether to strip the scheme. Return false to show scheme. (default: true)\n |
| 197 | 197 | * If true: `http://example.com => example.com` |
| 198 | 198 | */ |
| 199 | - if( false === apply_filters('gravityview_anchor_text_striphttp', true) ) { |
|
| 199 | + if (false === apply_filters('gravityview_anchor_text_striphttp', true)) { |
|
| 200 | 200 | |
| 201 | - if( isset( $parts['scheme'] ) ) { |
|
| 201 | + if (isset($parts['scheme'])) { |
|
| 202 | 202 | $return .= $parts['scheme']; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | * @param boolean $enable Whether to strip www. Return false to show www. (default: true)\n |
| 214 | 214 | * If true: `www.example.com => example.com` |
| 215 | 215 | */ |
| 216 | - $strip_www = apply_filters('gravityview_anchor_text_stripwww', true ); |
|
| 216 | + $strip_www = apply_filters('gravityview_anchor_text_stripwww', true); |
|
| 217 | 217 | |
| 218 | - if( $strip_www ) { |
|
| 219 | - $domain = str_replace('www.', '', $domain ); |
|
| 218 | + if ($strip_www) { |
|
| 219 | + $domain = str_replace('www.', '', $domain); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | $strip_subdomains = apply_filters('gravityview_anchor_text_nosubdomain', true); |
| 230 | 230 | |
| 231 | - if( $strip_subdomains ) { |
|
| 231 | + if ($strip_subdomains) { |
|
| 232 | 232 | |
| 233 | - $domain = _gravityview_strip_subdomain( $parts['host'] ); |
|
| 233 | + $domain = _gravityview_strip_subdomain($parts['host']); |
|
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | $root_only = apply_filters('gravityview_anchor_text_rootonly', true); |
| 248 | 248 | |
| 249 | - if( empty( $root_only ) ) { |
|
| 249 | + if (empty($root_only)) { |
|
| 250 | 250 | |
| 251 | - if( isset( $parts['path'] ) ) { |
|
| 251 | + if (isset($parts['path'])) { |
|
| 252 | 252 | $return .= $parts['path']; |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -259,11 +259,11 @@ discard block |
||
| 259 | 259 | * @param boolean $enable Whether to enable "root only". Return false to show full path. (default: true)\n |
| 260 | 260 | * If true: `http://example.com/?query=example => example.com` |
| 261 | 261 | */ |
| 262 | - $strip_query_string = apply_filters('gravityview_anchor_text_noquerystring', true ); |
|
| 262 | + $strip_query_string = apply_filters('gravityview_anchor_text_noquerystring', true); |
|
| 263 | 263 | |
| 264 | - if( empty( $strip_query_string ) ) { |
|
| 264 | + if (empty($strip_query_string)) { |
|
| 265 | 265 | |
| 266 | - if( isset( $parts['query'] ) ) { |
|
| 266 | + if (isset($parts['query'])) { |
|
| 267 | 267 | $return .= '?'.$parts['query']; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -279,9 +279,9 @@ discard block |
||
| 279 | 279 | * @param string $domain Domain to check if it's a TLD or subdomain |
| 280 | 280 | * @return string Extracted domain if it has a subdomain |
| 281 | 281 | */ |
| 282 | -function _gravityview_strip_subdomain( $string_maybe_has_subdomain ) { |
|
| 282 | +function _gravityview_strip_subdomain($string_maybe_has_subdomain) { |
|
| 283 | 283 | |
| 284 | - if( preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.(?:com\.|co\.|net\.|org\.|firm\.|me\.|school\.|law\.|gov\.|mod\.|msk\.|irkutsks\.|sa\.|act\.|police\.|plc\.|ac\.|tm\.|asso\.|biz\.|pro\.|cg\.|telememo\.)?[a-z\.]{2,6})$/i", $string_maybe_has_subdomain, $matches ) ) { |
|
| 284 | + if (preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.(?:com\.|co\.|net\.|org\.|firm\.|me\.|school\.|law\.|gov\.|mod\.|msk\.|irkutsks\.|sa\.|act\.|police\.|plc\.|ac\.|tm\.|asso\.|biz\.|pro\.|cg\.|telememo\.)?[a-z\.]{2,6})$/i", $string_maybe_has_subdomain, $matches)) { |
|
| 285 | 285 | return $matches['domain']; |
| 286 | 286 | } else { |
| 287 | 287 | return $string_maybe_has_subdomain; |
@@ -301,37 +301,37 @@ discard block |
||
| 301 | 301 | * @param boolean $allow_string_booleans Whether to check if 'yes', 'true' => `true` and 'no', 'false' => `false` |
| 302 | 302 | * @return boolean True: empty; false: not empty |
| 303 | 303 | */ |
| 304 | -function gv_empty( $value, $zero_is_empty = true, $allow_string_booleans = true ) { |
|
| 304 | +function gv_empty($value, $zero_is_empty = true, $allow_string_booleans = true) { |
|
| 305 | 305 | |
| 306 | - if( |
|
| 307 | - ! isset( $value ) // If it's not set, it's empty! |
|
| 306 | + if ( |
|
| 307 | + !isset($value) // If it's not set, it's empty! |
|
| 308 | 308 | || false === $value |
| 309 | 309 | || null === $value |
| 310 | 310 | || '' === $value // Empty string |
| 311 | 311 | || array() === $value // Empty array |
| 312 | - || ( is_object( $value ) && ! get_object_vars( $value ) ) // Empty object |
|
| 312 | + || (is_object($value) && !get_object_vars($value)) // Empty object |
|
| 313 | 313 | ) { |
| 314 | 314 | return true; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - if( is_string( $value ) && $allow_string_booleans ) { |
|
| 317 | + if (is_string($value) && $allow_string_booleans) { |
|
| 318 | 318 | |
| 319 | - $value = trim( $value ); |
|
| 320 | - $value = strtolower( $value ); |
|
| 319 | + $value = trim($value); |
|
| 320 | + $value = strtolower($value); |
|
| 321 | 321 | |
| 322 | - if ( in_array( $value, array( 'yes', 'true' ), true ) ) { |
|
| 322 | + if (in_array($value, array('yes', 'true'), true)) { |
|
| 323 | 323 | $value = true; |
| 324 | - } else if( in_array( $value, array( 'no', 'false' ), true ) ) { |
|
| 324 | + } else if (in_array($value, array('no', 'false'), true)) { |
|
| 325 | 325 | $value = false; |
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // If zero isn't empty, then if $value is a number and it's empty, it's zero. Thus, return false. |
| 330 | - if( ! $zero_is_empty && is_numeric( $value ) && empty( $value ) ) { |
|
| 330 | + if (!$zero_is_empty && is_numeric($value) && empty($value)) { |
|
| 331 | 331 | return false; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - return empty( $value ); |
|
| 334 | + return empty($value); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -344,15 +344,15 @@ discard block |
||
| 344 | 344 | * |
| 345 | 345 | * @return bool True: it's a valid datetime, formatted as expected. False: it's not a date formatted as expected. |
| 346 | 346 | */ |
| 347 | -function gravityview_is_valid_datetime( $datetime, $expected_format = 'Y-m-d' ) { |
|
| 347 | +function gravityview_is_valid_datetime($datetime, $expected_format = 'Y-m-d') { |
|
| 348 | 348 | |
| 349 | 349 | /** |
| 350 | 350 | * @var bool|DateTime False if not a valid date, (like a relative date). DateTime if a date was created. |
| 351 | 351 | */ |
| 352 | - $formatted_date = DateTime::createFromFormat( $expected_format, $datetime ); |
|
| 352 | + $formatted_date = DateTime::createFromFormat($expected_format, $datetime); |
|
| 353 | 353 | |
| 354 | 354 | /** |
| 355 | 355 | * @see http://stackoverflow.com/a/19271434/480856 |
| 356 | 356 | */ |
| 357 | - return ( $formatted_date && $formatted_date->format( $expected_format ) === $datetime ); |
|
| 357 | + return ($formatted_date && $formatted_date->format($expected_format) === $datetime); |
|
| 358 | 358 | } |
| 359 | 359 | \ No newline at end of file |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | * @uses api_request() |
| 69 | 69 | * |
| 70 | 70 | * @param array $_transient_data Update array build by WordPress. |
| 71 | - * @return array Modified update array with custom plugin data. |
|
| 71 | + * @return stdClass Modified update array with custom plugin data. |
|
| 72 | 72 | */ |
| 73 | 73 | function check_update( $_transient_data ) { |
| 74 | 74 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | //set_site_transient( 'update_plugins', null ); |
| 5 | 5 | |
| 6 | 6 | // Exit if accessed directly |
| 7 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 7 | +if (!defined('ABSPATH')) exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Allows plugins to use their own update API. |
@@ -29,16 +29,16 @@ discard block |
||
| 29 | 29 | * @param string $_plugin_file Path to the plugin file. |
| 30 | 30 | * @param array $_api_data Optional data to send with API calls. |
| 31 | 31 | */ |
| 32 | - function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 33 | - $this->api_url = trailingslashit( $_api_url ); |
|
| 32 | + function __construct($_api_url, $_plugin_file, $_api_data = null) { |
|
| 33 | + $this->api_url = trailingslashit($_api_url); |
|
| 34 | 34 | $this->api_data = $_api_data; |
| 35 | - $this->name = plugin_basename( $_plugin_file ); |
|
| 36 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
| 35 | + $this->name = plugin_basename($_plugin_file); |
|
| 36 | + $this->slug = basename($_plugin_file, '.php'); |
|
| 37 | 37 | $this->version = $_api_data['version']; |
| 38 | 38 | |
| 39 | 39 | // Set up hooks. |
| 40 | 40 | $this->init(); |
| 41 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
| 41 | + add_action('admin_init', array($this, 'show_changelog')); |
|
| 42 | 42 | |
| 43 | 43 | } |
| 44 | 44 | |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | 52 | public function init() { |
| 53 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 54 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
| 53 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
| 54 | + add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3); |
|
| 55 | 55 | |
| 56 | - remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10, 2 ); |
|
| 57 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
| 56 | + remove_action('after_plugin_row_'.$this->name, 'wp_plugin_update_row', 10, 2); |
|
| 57 | + add_action('after_plugin_row_'.$this->name, array($this, 'show_update_notification'), 10, 2); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -70,32 +70,32 @@ discard block |
||
| 70 | 70 | * @param array $_transient_data Update array build by WordPress. |
| 71 | 71 | * @return array Modified update array with custom plugin data. |
| 72 | 72 | */ |
| 73 | - function check_update( $_transient_data ) { |
|
| 73 | + function check_update($_transient_data) { |
|
| 74 | 74 | |
| 75 | 75 | global $pagenow; |
| 76 | 76 | |
| 77 | - if( ! is_object( $_transient_data ) ) { |
|
| 77 | + if (!is_object($_transient_data)) { |
|
| 78 | 78 | $_transient_data = new stdClass; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if( 'plugins.php' == $pagenow && is_multisite() ) { |
|
| 81 | + if ('plugins.php' == $pagenow && is_multisite()) { |
|
| 82 | 82 | return $_transient_data; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
| 85 | + if (empty($_transient_data->response) || empty($_transient_data->response[$this->name])) { |
|
| 86 | 86 | |
| 87 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 87 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
| 88 | 88 | |
| 89 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
| 89 | + if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) { |
|
| 90 | 90 | |
| 91 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 91 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
| 92 | 92 | |
| 93 | - $_transient_data->response[ $this->name ] = $version_info; |
|
| 93 | + $_transient_data->response[$this->name] = $version_info; |
|
| 94 | 94 | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $_transient_data->last_checked = time(); |
| 98 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
| 98 | + $_transient_data->checked[$this->name] = $this->version; |
|
| 99 | 99 | |
| 100 | 100 | } |
| 101 | 101 | |
@@ -110,86 +110,86 @@ discard block |
||
| 110 | 110 | * @param string $file |
| 111 | 111 | * @param array $plugin |
| 112 | 112 | */ |
| 113 | - public function show_update_notification( $file, $plugin ) { |
|
| 113 | + public function show_update_notification($file, $plugin) { |
|
| 114 | 114 | |
| 115 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 115 | + if (!current_user_can('update_plugins')) { |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if( ! is_multisite() ) { |
|
| 119 | + if (!is_multisite()) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if ( $this->name != $file ) { |
|
| 123 | + if ($this->name != $file) { |
|
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Remove our filter on the site transient |
| 128 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
| 128 | + remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10); |
|
| 129 | 129 | |
| 130 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
| 130 | + $update_cache = get_site_transient('update_plugins'); |
|
| 131 | 131 | |
| 132 | - $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); |
|
| 132 | + $update_cache = is_object($update_cache) ? $update_cache : new stdClass(); |
|
| 133 | 133 | |
| 134 | - if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
| 134 | + if (empty($update_cache->response) || empty($update_cache->response[$this->name])) { |
|
| 135 | 135 | |
| 136 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
| 137 | - $version_info = get_transient( $cache_key ); |
|
| 136 | + $cache_key = md5('edd_plugin_'.sanitize_key($this->name).'_version_info'); |
|
| 137 | + $version_info = get_transient($cache_key); |
|
| 138 | 138 | |
| 139 | - if( false === $version_info ) { |
|
| 139 | + if (false === $version_info) { |
|
| 140 | 140 | |
| 141 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 141 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
| 142 | 142 | |
| 143 | - set_transient( $cache_key, $version_info, 3600 ); |
|
| 143 | + set_transient($cache_key, $version_info, 3600); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
| 147 | - if( ! is_object( $version_info ) ) { |
|
| 147 | + if (!is_object($version_info)) { |
|
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 151 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
| 152 | 152 | |
| 153 | - $update_cache->response[ $this->name ] = $version_info; |
|
| 153 | + $update_cache->response[$this->name] = $version_info; |
|
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $update_cache->last_checked = time(); |
| 158 | - $update_cache->checked[ $this->name ] = $this->version; |
|
| 158 | + $update_cache->checked[$this->name] = $this->version; |
|
| 159 | 159 | |
| 160 | - set_site_transient( 'update_plugins', $update_cache ); |
|
| 160 | + set_site_transient('update_plugins', $update_cache); |
|
| 161 | 161 | |
| 162 | 162 | } else { |
| 163 | 163 | |
| 164 | - $version_info = $update_cache->response[ $this->name ]; |
|
| 164 | + $version_info = $update_cache->response[$this->name]; |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Restore our filter |
| 169 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 169 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
| 170 | 170 | |
| 171 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 171 | + if (!empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) { |
|
| 172 | 172 | |
| 173 | 173 | // build a plugin list row, with update notification |
| 174 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
| 175 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 174 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
| 175 | + echo '<tr class="plugin-update-tr"><td colspan="'.$wp_list_table->get_column_count().'" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 176 | 176 | |
| 177 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
| 177 | + $changelog_link = self_admin_url('index.php?edd_sl_action=view_plugin_changelog&plugin='.$this->name.'&slug='.$this->slug.'&TB_iframe=true&width=772&height=911'); |
|
| 178 | 178 | |
| 179 | - if ( empty( $version_info->download_link ) ) { |
|
| 179 | + if (empty($version_info->download_link)) { |
|
| 180 | 180 | printf( |
| 181 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'gravityview' ), |
|
| 182 | - esc_html( $version_info->name ), |
|
| 183 | - esc_url( $changelog_link ), |
|
| 184 | - esc_html( $version_info->new_version ) |
|
| 181 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'gravityview'), |
|
| 182 | + esc_html($version_info->name), |
|
| 183 | + esc_url($changelog_link), |
|
| 184 | + esc_html($version_info->new_version) |
|
| 185 | 185 | ); |
| 186 | 186 | } else { |
| 187 | 187 | printf( |
| 188 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'gravityview' ), |
|
| 189 | - esc_html( $version_info->name ), |
|
| 190 | - esc_url( $changelog_link ), |
|
| 191 | - esc_html( $version_info->new_version ), |
|
| 192 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
| 188 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'gravityview'), |
|
| 189 | + esc_html($version_info->name), |
|
| 190 | + esc_url($changelog_link), |
|
| 191 | + esc_html($version_info->new_version), |
|
| 192 | + esc_url(wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=').$this->name, 'upgrade-plugin_'.$this->name)) |
|
| 193 | 193 | ); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -208,16 +208,16 @@ discard block |
||
| 208 | 208 | * @param object $_args |
| 209 | 209 | * @return object $_data |
| 210 | 210 | */ |
| 211 | - function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
| 211 | + function plugins_api_filter($_data, $_action = '', $_args = null) { |
|
| 212 | 212 | |
| 213 | 213 | |
| 214 | - if ( $_action != 'plugin_information' ) { |
|
| 214 | + if ($_action != 'plugin_information') { |
|
| 215 | 215 | |
| 216 | 216 | return $_data; |
| 217 | 217 | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
| 220 | + if (!isset($_args->slug) || ($_args->slug != $this->slug)) { |
|
| 221 | 221 | |
| 222 | 222 | return $_data; |
| 223 | 223 | |
@@ -232,9 +232,9 @@ discard block |
||
| 232 | 232 | ) |
| 233 | 233 | ); |
| 234 | 234 | |
| 235 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
| 235 | + $api_response = $this->api_request('plugin_information', $to_send); |
|
| 236 | 236 | |
| 237 | - if ( false !== $api_response ) { |
|
| 237 | + if (false !== $api_response) { |
|
| 238 | 238 | $_data = $api_response; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | * @param string $url |
| 250 | 250 | * @return object $array |
| 251 | 251 | */ |
| 252 | - function http_request_args( $args, $url ) { |
|
| 252 | + function http_request_args($args, $url) { |
|
| 253 | 253 | // If it is an https request and we are performing a package download, disable ssl verification |
| 254 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
| 254 | + if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) { |
|
| 255 | 255 | $args['sslverify'] = false; |
| 256 | 256 | } |
| 257 | 257 | return $args; |
@@ -268,43 +268,43 @@ discard block |
||
| 268 | 268 | * @param array $_data Parameters for the API action. |
| 269 | 269 | * @return false|object |
| 270 | 270 | */ |
| 271 | - private function api_request( $_action, $_data ) { |
|
| 271 | + private function api_request($_action, $_data) { |
|
| 272 | 272 | |
| 273 | 273 | global $wp_version; |
| 274 | 274 | |
| 275 | - $data = array_merge( $this->api_data, $_data ); |
|
| 275 | + $data = array_merge($this->api_data, $_data); |
|
| 276 | 276 | |
| 277 | - if ( $data['slug'] != $this->slug ) { |
|
| 277 | + if ($data['slug'] != $this->slug) { |
|
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if( $this->api_url == home_url() ) { |
|
| 281 | + if ($this->api_url == home_url()) { |
|
| 282 | 282 | return false; // Don't allow a plugin to ping itself |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $api_params = array( |
| 286 | 286 | 'edd_action' => 'get_version', |
| 287 | - 'license' => ! empty( $data['license'] ) ? $data['license'] : '', |
|
| 288 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
| 289 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
| 287 | + 'license' => !empty($data['license']) ? $data['license'] : '', |
|
| 288 | + 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, |
|
| 289 | + 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, |
|
| 290 | 290 | 'slug' => $data['slug'], |
| 291 | 291 | 'author' => $data['author'], |
| 292 | 292 | 'url' => home_url() |
| 293 | 293 | ); |
| 294 | 294 | |
| 295 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
| 295 | + $request = wp_remote_post($this->api_url, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); |
|
| 296 | 296 | |
| 297 | - if ( ! is_wp_error( $request ) ) { |
|
| 298 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
| 297 | + if (!is_wp_error($request)) { |
|
| 298 | + $request = json_decode(wp_remote_retrieve_body($request)); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( $request ) { |
|
| 302 | - if( isset( $request->sections ) ) { |
|
| 303 | - $request->sections = maybe_unserialize( $request->sections ); |
|
| 301 | + if ($request) { |
|
| 302 | + if (isset($request->sections)) { |
|
| 303 | + $request->sections = maybe_unserialize($request->sections); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if( isset( $request->banners ) ) { |
|
| 307 | - $request->banners = (array)maybe_unserialize( $request->banners ); |
|
| 306 | + if (isset($request->banners)) { |
|
| 307 | + $request->banners = (array)maybe_unserialize($request->banners); |
|
| 308 | 308 | } |
| 309 | 309 | } else { |
| 310 | 310 | $request = false; |
@@ -316,26 +316,26 @@ discard block |
||
| 316 | 316 | public function show_changelog() { |
| 317 | 317 | |
| 318 | 318 | |
| 319 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
| 319 | + if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action']) { |
|
| 320 | 320 | return; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
| 323 | + if (empty($_REQUEST['plugin'])) { |
|
| 324 | 324 | return; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if( empty( $_REQUEST['slug'] ) ) { |
|
| 327 | + if (empty($_REQUEST['slug'])) { |
|
| 328 | 328 | return; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 332 | - wp_die( __( 'You do not have permission to install plugin updates', 'gravityview' ), __( 'Error', 'gravityview' ), array( 'response' => 403 ) ); |
|
| 331 | + if (!current_user_can('update_plugins')) { |
|
| 332 | + wp_die(__('You do not have permission to install plugin updates', 'gravityview'), __('Error', 'gravityview'), array('response' => 403)); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
| 335 | + $response = $this->api_request('plugin_latest_version', array('slug' => $_REQUEST['slug'])); |
|
| 336 | 336 | |
| 337 | - if( $response && isset( $response->sections['changelog'] ) ) { |
|
| 338 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
| 337 | + if ($response && isset($response->sections['changelog'])) { |
|
| 338 | + echo '<div style="background:#fff;padding:10px;">'.$response->sections['changelog'].'</div>'; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -4,7 +4,9 @@ |
||
| 4 | 4 | //set_site_transient( 'update_plugins', null ); |
| 5 | 5 | |
| 6 | 6 | // Exit if accessed directly |
| 7 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 7 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | + exit; |
|
| 9 | +} |
|
| 8 | 10 | |
| 9 | 11 | /** |
| 10 | 12 | * Allows plugins to use their own update API. |
@@ -10,6 +10,10 @@ discard block |
||
| 10 | 10 | * WordPress Importer class for managing parsing of WXR files. |
| 11 | 11 | */ |
| 12 | 12 | class WXR_Parser { |
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * @param string $file |
|
| 16 | + */ |
|
| 13 | 17 | function parse( $file ) { |
| 14 | 18 | // Attempt to use proper XML parsers first |
| 15 | 19 | if ( extension_loaded( 'simplexml' ) ) { |
@@ -479,6 +483,9 @@ discard block |
||
| 479 | 483 | ); |
| 480 | 484 | } |
| 481 | 485 | |
| 486 | + /** |
|
| 487 | + * @param string $tag |
|
| 488 | + */ |
|
| 482 | 489 | function get_tag( $string, $tag ) { |
| 483 | 490 | preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return ); |
| 484 | 491 | if ( isset( $return[1] ) ) { |
@@ -500,6 +507,9 @@ discard block |
||
| 500 | 507 | return $return; |
| 501 | 508 | } |
| 502 | 509 | |
| 510 | + /** |
|
| 511 | + * @param string $c |
|
| 512 | + */ |
|
| 503 | 513 | function process_category( $c ) { |
| 504 | 514 | return array( |
| 505 | 515 | 'term_id' => $this->get_tag( $c, 'wp:term_id' ), |
@@ -510,6 +520,9 @@ discard block |
||
| 510 | 520 | ); |
| 511 | 521 | } |
| 512 | 522 | |
| 523 | + /** |
|
| 524 | + * @param string $t |
|
| 525 | + */ |
|
| 513 | 526 | function process_tag( $t ) { |
| 514 | 527 | return array( |
| 515 | 528 | 'term_id' => $this->get_tag( $t, 'wp:term_id' ), |
@@ -519,6 +532,9 @@ discard block |
||
| 519 | 532 | ); |
| 520 | 533 | } |
| 521 | 534 | |
| 535 | + /** |
|
| 536 | + * @param string $t |
|
| 537 | + */ |
|
| 522 | 538 | function process_term( $t ) { |
| 523 | 539 | return array( |
| 524 | 540 | 'term_id' => $this->get_tag( $t, 'wp:term_id' ), |
@@ -530,6 +546,9 @@ discard block |
||
| 530 | 546 | ); |
| 531 | 547 | } |
| 532 | 548 | |
| 549 | + /** |
|
| 550 | + * @param string $a |
|
| 551 | + */ |
|
| 533 | 552 | function process_author( $a ) { |
| 534 | 553 | return array( |
| 535 | 554 | 'author_id' => $this->get_tag( $a, 'wp:author_id' ), |
@@ -541,6 +560,9 @@ discard block |
||
| 541 | 560 | ); |
| 542 | 561 | } |
| 543 | 562 | |
| 563 | + /** |
|
| 564 | + * @param string $post |
|
| 565 | + */ |
|
| 544 | 566 | function process_post( $post ) { |
| 545 | 567 | $post_id = $this->get_tag( $post, 'wp:post_id' ); |
| 546 | 568 | $post_title = $this->get_tag( $post, 'title' ); |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Copied from WordPress Importer plugin |
|
| 4 | - * http://wordpress.org/extend/plugins/wordpress-importer/ |
|
| 5 | - * Version: 0.6.1 |
|
| 6 | - * License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|
| 7 | - */ |
|
| 3 | + * Copied from WordPress Importer plugin |
|
| 4 | + * http://wordpress.org/extend/plugins/wordpress-importer/ |
|
| 5 | + * Version: 0.6.1 |
|
| 6 | + * License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * WordPress Importer class for managing parsing of WXR files. |
@@ -10,42 +10,42 @@ discard block |
||
| 10 | 10 | * WordPress Importer class for managing parsing of WXR files. |
| 11 | 11 | */ |
| 12 | 12 | class WXR_Parser { |
| 13 | - function parse( $file ) { |
|
| 13 | + function parse($file) { |
|
| 14 | 14 | // Attempt to use proper XML parsers first |
| 15 | - if ( extension_loaded( 'simplexml' ) ) { |
|
| 15 | + if (extension_loaded('simplexml')) { |
|
| 16 | 16 | $parser = new WXR_Parser_SimpleXML; |
| 17 | - $result = $parser->parse( $file ); |
|
| 17 | + $result = $parser->parse($file); |
|
| 18 | 18 | |
| 19 | 19 | // If SimpleXML succeeds or this is an invalid WXR file then return the results |
| 20 | - if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) |
|
| 20 | + if (!is_wp_error($result) || 'SimpleXML_parse_error' != $result->get_error_code()) |
|
| 21 | 21 | return $result; |
| 22 | - } else if ( extension_loaded( 'xml' ) ) { |
|
| 22 | + } else if (extension_loaded('xml')) { |
|
| 23 | 23 | $parser = new WXR_Parser_XML; |
| 24 | - $result = $parser->parse( $file ); |
|
| 24 | + $result = $parser->parse($file); |
|
| 25 | 25 | |
| 26 | 26 | // If XMLParser succeeds or this is an invalid WXR file then return the results |
| 27 | - if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) |
|
| 27 | + if (!is_wp_error($result) || 'XML_parse_error' != $result->get_error_code()) |
|
| 28 | 28 | return $result; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // We have a malformed XML file, so display the error and fallthrough to regex |
| 32 | - if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) { |
|
| 32 | + if (isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG) { |
|
| 33 | 33 | echo '<pre>'; |
| 34 | - if ( 'SimpleXML_parse_error' == $result->get_error_code() ) { |
|
| 35 | - foreach ( $result->get_error_data() as $error ) |
|
| 36 | - echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n"; |
|
| 37 | - } else if ( 'XML_parse_error' == $result->get_error_code() ) { |
|
| 34 | + if ('SimpleXML_parse_error' == $result->get_error_code()) { |
|
| 35 | + foreach ($result->get_error_data() as $error) |
|
| 36 | + echo $error->line.':'.$error->column.' '.esc_html($error->message)."\n"; |
|
| 37 | + } else if ('XML_parse_error' == $result->get_error_code()) { |
|
| 38 | 38 | $error = $result->get_error_data(); |
| 39 | - echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] ); |
|
| 39 | + echo $error[0].':'.$error[1].' '.esc_html($error[2]); |
|
| 40 | 40 | } |
| 41 | 41 | echo '</pre>'; |
| 42 | - echo '<p><strong>' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . '</strong><br />'; |
|
| 43 | - echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '</p>'; |
|
| 42 | + echo '<p><strong>'.__('There was an error when reading this WXR file', 'wordpress-importer').'</strong><br />'; |
|
| 43 | + echo __('Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer').'</p>'; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // use regular expressions if nothing else available or this is bad XML |
| 47 | 47 | $parser = new WXR_Parser_Regex; |
| 48 | - return $parser->parse( $file ); |
|
| 48 | + return $parser->parse($file); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -53,171 +53,171 @@ discard block |
||
| 53 | 53 | * WXR Parser that makes use of the SimpleXML PHP extension. |
| 54 | 54 | */ |
| 55 | 55 | class WXR_Parser_SimpleXML { |
| 56 | - function parse( $file ) { |
|
| 56 | + function parse($file) { |
|
| 57 | 57 | $authors = $posts = $categories = $tags = $terms = array(); |
| 58 | 58 | |
| 59 | 59 | $internal_errors = libxml_use_internal_errors(true); |
| 60 | 60 | |
| 61 | 61 | $dom = new DOMDocument; |
| 62 | 62 | $old_value = null; |
| 63 | - if ( function_exists( 'libxml_disable_entity_loader' ) ) { |
|
| 64 | - $old_value = libxml_disable_entity_loader( true ); |
|
| 63 | + if (function_exists('libxml_disable_entity_loader')) { |
|
| 64 | + $old_value = libxml_disable_entity_loader(true); |
|
| 65 | 65 | } |
| 66 | - $success = $dom->loadXML( file_get_contents( $file ) ); |
|
| 67 | - if ( ! is_null( $old_value ) ) { |
|
| 68 | - libxml_disable_entity_loader( $old_value ); |
|
| 66 | + $success = $dom->loadXML(file_get_contents($file)); |
|
| 67 | + if (!is_null($old_value)) { |
|
| 68 | + libxml_disable_entity_loader($old_value); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if ( ! $success || isset( $dom->doctype ) ) { |
|
| 72 | - return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); |
|
| 71 | + if (!$success || isset($dom->doctype)) { |
|
| 72 | + return new WP_Error('SimpleXML_parse_error', __('There was an error when reading this WXR file', 'wordpress-importer'), libxml_get_errors()); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $xml = simplexml_import_dom( $dom ); |
|
| 76 | - unset( $dom ); |
|
| 75 | + $xml = simplexml_import_dom($dom); |
|
| 76 | + unset($dom); |
|
| 77 | 77 | |
| 78 | 78 | // halt if loading produces an error |
| 79 | - if ( ! $xml ) |
|
| 80 | - return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); |
|
| 79 | + if (!$xml) |
|
| 80 | + return new WP_Error('SimpleXML_parse_error', __('There was an error when reading this WXR file', 'wordpress-importer'), libxml_get_errors()); |
|
| 81 | 81 | |
| 82 | 82 | $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version'); |
| 83 | - if ( ! $wxr_version ) |
|
| 84 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 83 | + if (!$wxr_version) |
|
| 84 | + return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer')); |
|
| 85 | 85 | |
| 86 | - $wxr_version = (string) trim( $wxr_version[0] ); |
|
| 86 | + $wxr_version = (string)trim($wxr_version[0]); |
|
| 87 | 87 | // confirm that we are dealing with the correct file format |
| 88 | - if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) |
|
| 89 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 88 | + if (!preg_match('/^\d+\.\d+$/', $wxr_version)) |
|
| 89 | + return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer')); |
|
| 90 | 90 | |
| 91 | 91 | $base_url = $xml->xpath('/rss/channel/wp:base_site_url'); |
| 92 | - $base_url = isset($base_url[0]) ? (string) trim( $base_url[0] ) : ''; // Modified by GravityView: Check if base_url exists; the GV import files may exclude them. |
|
| 92 | + $base_url = isset($base_url[0]) ? (string)trim($base_url[0]) : ''; // Modified by GravityView: Check if base_url exists; the GV import files may exclude them. |
|
| 93 | 93 | |
| 94 | 94 | $namespaces = $xml->getDocNamespaces(); |
| 95 | - if ( ! isset( $namespaces['wp'] ) ) |
|
| 95 | + if (!isset($namespaces['wp'])) |
|
| 96 | 96 | $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
| 97 | - if ( ! isset( $namespaces['excerpt'] ) ) |
|
| 97 | + if (!isset($namespaces['excerpt'])) |
|
| 98 | 98 | $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
| 99 | 99 | |
| 100 | 100 | // grab authors |
| 101 | - foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) { |
|
| 102 | - $a = $author_arr->children( $namespaces['wp'] ); |
|
| 103 | - $login = (string) $a->author_login; |
|
| 101 | + foreach ($xml->xpath('/rss/channel/wp:author') as $author_arr) { |
|
| 102 | + $a = $author_arr->children($namespaces['wp']); |
|
| 103 | + $login = (string)$a->author_login; |
|
| 104 | 104 | $authors[$login] = array( |
| 105 | - 'author_id' => (int) $a->author_id, |
|
| 105 | + 'author_id' => (int)$a->author_id, |
|
| 106 | 106 | 'author_login' => $login, |
| 107 | - 'author_email' => (string) $a->author_email, |
|
| 108 | - 'author_display_name' => (string) $a->author_display_name, |
|
| 109 | - 'author_first_name' => (string) $a->author_first_name, |
|
| 110 | - 'author_last_name' => (string) $a->author_last_name |
|
| 107 | + 'author_email' => (string)$a->author_email, |
|
| 108 | + 'author_display_name' => (string)$a->author_display_name, |
|
| 109 | + 'author_first_name' => (string)$a->author_first_name, |
|
| 110 | + 'author_last_name' => (string)$a->author_last_name |
|
| 111 | 111 | ); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // grab cats, tags and terms |
| 115 | - foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) { |
|
| 116 | - $t = $term_arr->children( $namespaces['wp'] ); |
|
| 115 | + foreach ($xml->xpath('/rss/channel/wp:category') as $term_arr) { |
|
| 116 | + $t = $term_arr->children($namespaces['wp']); |
|
| 117 | 117 | $categories[] = array( |
| 118 | - 'term_id' => (int) $t->term_id, |
|
| 119 | - 'category_nicename' => (string) $t->category_nicename, |
|
| 120 | - 'category_parent' => (string) $t->category_parent, |
|
| 121 | - 'cat_name' => (string) $t->cat_name, |
|
| 122 | - 'category_description' => (string) $t->category_description |
|
| 118 | + 'term_id' => (int)$t->term_id, |
|
| 119 | + 'category_nicename' => (string)$t->category_nicename, |
|
| 120 | + 'category_parent' => (string)$t->category_parent, |
|
| 121 | + 'cat_name' => (string)$t->cat_name, |
|
| 122 | + 'category_description' => (string)$t->category_description |
|
| 123 | 123 | ); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) { |
|
| 127 | - $t = $term_arr->children( $namespaces['wp'] ); |
|
| 126 | + foreach ($xml->xpath('/rss/channel/wp:tag') as $term_arr) { |
|
| 127 | + $t = $term_arr->children($namespaces['wp']); |
|
| 128 | 128 | $tags[] = array( |
| 129 | - 'term_id' => (int) $t->term_id, |
|
| 130 | - 'tag_slug' => (string) $t->tag_slug, |
|
| 131 | - 'tag_name' => (string) $t->tag_name, |
|
| 132 | - 'tag_description' => (string) $t->tag_description |
|
| 129 | + 'term_id' => (int)$t->term_id, |
|
| 130 | + 'tag_slug' => (string)$t->tag_slug, |
|
| 131 | + 'tag_name' => (string)$t->tag_name, |
|
| 132 | + 'tag_description' => (string)$t->tag_description |
|
| 133 | 133 | ); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) { |
|
| 137 | - $t = $term_arr->children( $namespaces['wp'] ); |
|
| 136 | + foreach ($xml->xpath('/rss/channel/wp:term') as $term_arr) { |
|
| 137 | + $t = $term_arr->children($namespaces['wp']); |
|
| 138 | 138 | $terms[] = array( |
| 139 | - 'term_id' => (int) $t->term_id, |
|
| 140 | - 'term_taxonomy' => (string) $t->term_taxonomy, |
|
| 141 | - 'slug' => (string) $t->term_slug, |
|
| 142 | - 'term_parent' => (string) $t->term_parent, |
|
| 143 | - 'term_name' => (string) $t->term_name, |
|
| 144 | - 'term_description' => (string) $t->term_description |
|
| 139 | + 'term_id' => (int)$t->term_id, |
|
| 140 | + 'term_taxonomy' => (string)$t->term_taxonomy, |
|
| 141 | + 'slug' => (string)$t->term_slug, |
|
| 142 | + 'term_parent' => (string)$t->term_parent, |
|
| 143 | + 'term_name' => (string)$t->term_name, |
|
| 144 | + 'term_description' => (string)$t->term_description |
|
| 145 | 145 | ); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // grab posts |
| 149 | - foreach ( $xml->channel->item as $item ) { |
|
| 149 | + foreach ($xml->channel->item as $item) { |
|
| 150 | 150 | $post = array( |
| 151 | - 'post_title' => (string) $item->title, |
|
| 152 | - 'guid' => (string) $item->guid, |
|
| 151 | + 'post_title' => (string)$item->title, |
|
| 152 | + 'guid' => (string)$item->guid, |
|
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | - $dc = $item->children( 'http://purl.org/dc/elements/1.1/' ); |
|
| 156 | - $post['post_author'] = (string) $dc->creator; |
|
| 157 | - |
|
| 158 | - $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' ); |
|
| 159 | - $excerpt = $item->children( $namespaces['excerpt'] ); |
|
| 160 | - $post['post_content'] = (string) $content->encoded; |
|
| 161 | - $post['post_excerpt'] = (string) $excerpt->encoded; |
|
| 162 | - |
|
| 163 | - $wp = $item->children( $namespaces['wp'] ); |
|
| 164 | - $post['post_id'] = (int) $wp->post_id; |
|
| 165 | - $post['post_date'] = (string) $wp->post_date; |
|
| 166 | - $post['post_date_gmt'] = (string) $wp->post_date_gmt; |
|
| 167 | - $post['comment_status'] = (string) $wp->comment_status; |
|
| 168 | - $post['ping_status'] = (string) $wp->ping_status; |
|
| 169 | - $post['post_name'] = (string) $wp->post_name; |
|
| 170 | - $post['status'] = (string) $wp->status; |
|
| 171 | - $post['post_parent'] = (int) $wp->post_parent; |
|
| 172 | - $post['menu_order'] = (int) $wp->menu_order; |
|
| 173 | - $post['post_type'] = (string) $wp->post_type; |
|
| 174 | - $post['post_password'] = (string) $wp->post_password; |
|
| 175 | - $post['is_sticky'] = (int) $wp->is_sticky; |
|
| 176 | - |
|
| 177 | - if ( isset($wp->attachment_url) ) |
|
| 178 | - $post['attachment_url'] = (string) $wp->attachment_url; |
|
| 179 | - |
|
| 180 | - foreach ( $item->category as $c ) { |
|
| 155 | + $dc = $item->children('http://purl.org/dc/elements/1.1/'); |
|
| 156 | + $post['post_author'] = (string)$dc->creator; |
|
| 157 | + |
|
| 158 | + $content = $item->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 159 | + $excerpt = $item->children($namespaces['excerpt']); |
|
| 160 | + $post['post_content'] = (string)$content->encoded; |
|
| 161 | + $post['post_excerpt'] = (string)$excerpt->encoded; |
|
| 162 | + |
|
| 163 | + $wp = $item->children($namespaces['wp']); |
|
| 164 | + $post['post_id'] = (int)$wp->post_id; |
|
| 165 | + $post['post_date'] = (string)$wp->post_date; |
|
| 166 | + $post['post_date_gmt'] = (string)$wp->post_date_gmt; |
|
| 167 | + $post['comment_status'] = (string)$wp->comment_status; |
|
| 168 | + $post['ping_status'] = (string)$wp->ping_status; |
|
| 169 | + $post['post_name'] = (string)$wp->post_name; |
|
| 170 | + $post['status'] = (string)$wp->status; |
|
| 171 | + $post['post_parent'] = (int)$wp->post_parent; |
|
| 172 | + $post['menu_order'] = (int)$wp->menu_order; |
|
| 173 | + $post['post_type'] = (string)$wp->post_type; |
|
| 174 | + $post['post_password'] = (string)$wp->post_password; |
|
| 175 | + $post['is_sticky'] = (int)$wp->is_sticky; |
|
| 176 | + |
|
| 177 | + if (isset($wp->attachment_url)) |
|
| 178 | + $post['attachment_url'] = (string)$wp->attachment_url; |
|
| 179 | + |
|
| 180 | + foreach ($item->category as $c) { |
|
| 181 | 181 | $att = $c->attributes(); |
| 182 | - if ( isset( $att['nicename'] ) ) |
|
| 182 | + if (isset($att['nicename'])) |
|
| 183 | 183 | $post['terms'][] = array( |
| 184 | - 'name' => (string) $c, |
|
| 185 | - 'slug' => (string) $att['nicename'], |
|
| 186 | - 'domain' => (string) $att['domain'] |
|
| 184 | + 'name' => (string)$c, |
|
| 185 | + 'slug' => (string)$att['nicename'], |
|
| 186 | + 'domain' => (string)$att['domain'] |
|
| 187 | 187 | ); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - foreach ( $wp->postmeta as $meta ) { |
|
| 190 | + foreach ($wp->postmeta as $meta) { |
|
| 191 | 191 | $post['postmeta'][] = array( |
| 192 | - 'key' => (string) $meta->meta_key, |
|
| 193 | - 'value' => (string) $meta->meta_value |
|
| 192 | + 'key' => (string)$meta->meta_key, |
|
| 193 | + 'value' => (string)$meta->meta_value |
|
| 194 | 194 | ); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - foreach ( $wp->comment as $comment ) { |
|
| 197 | + foreach ($wp->comment as $comment) { |
|
| 198 | 198 | $meta = array(); |
| 199 | - if ( isset( $comment->commentmeta ) ) { |
|
| 200 | - foreach ( $comment->commentmeta as $m ) { |
|
| 199 | + if (isset($comment->commentmeta)) { |
|
| 200 | + foreach ($comment->commentmeta as $m) { |
|
| 201 | 201 | $meta[] = array( |
| 202 | - 'key' => (string) $m->meta_key, |
|
| 203 | - 'value' => (string) $m->meta_value |
|
| 202 | + 'key' => (string)$m->meta_key, |
|
| 203 | + 'value' => (string)$m->meta_value |
|
| 204 | 204 | ); |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $post['comments'][] = array( |
| 209 | - 'comment_id' => (int) $comment->comment_id, |
|
| 210 | - 'comment_author' => (string) $comment->comment_author, |
|
| 211 | - 'comment_author_email' => (string) $comment->comment_author_email, |
|
| 212 | - 'comment_author_IP' => (string) $comment->comment_author_IP, |
|
| 213 | - 'comment_author_url' => (string) $comment->comment_author_url, |
|
| 214 | - 'comment_date' => (string) $comment->comment_date, |
|
| 215 | - 'comment_date_gmt' => (string) $comment->comment_date_gmt, |
|
| 216 | - 'comment_content' => (string) $comment->comment_content, |
|
| 217 | - 'comment_approved' => (string) $comment->comment_approved, |
|
| 218 | - 'comment_type' => (string) $comment->comment_type, |
|
| 219 | - 'comment_parent' => (string) $comment->comment_parent, |
|
| 220 | - 'comment_user_id' => (int) $comment->comment_user_id, |
|
| 209 | + 'comment_id' => (int)$comment->comment_id, |
|
| 210 | + 'comment_author' => (string)$comment->comment_author, |
|
| 211 | + 'comment_author_email' => (string)$comment->comment_author_email, |
|
| 212 | + 'comment_author_IP' => (string)$comment->comment_author_IP, |
|
| 213 | + 'comment_author_url' => (string)$comment->comment_author_url, |
|
| 214 | + 'comment_date' => (string)$comment->comment_date, |
|
| 215 | + 'comment_date_gmt' => (string)$comment->comment_date_gmt, |
|
| 216 | + 'comment_content' => (string)$comment->comment_content, |
|
| 217 | + 'comment_approved' => (string)$comment->comment_approved, |
|
| 218 | + 'comment_type' => (string)$comment->comment_type, |
|
| 219 | + 'comment_parent' => (string)$comment->comment_parent, |
|
| 220 | + 'comment_user_id' => (int)$comment->comment_user_id, |
|
| 221 | 221 | 'commentmeta' => $meta, |
| 222 | 222 | ); |
| 223 | 223 | } |
@@ -251,32 +251,32 @@ discard block |
||
| 251 | 251 | ); |
| 252 | 252 | var $wp_sub_tags = array( |
| 253 | 253 | 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url', |
| 254 | - 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content', |
|
| 254 | + 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content', |
|
| 255 | 255 | 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id', |
| 256 | 256 | ); |
| 257 | 257 | |
| 258 | - function parse( $file ) { |
|
| 258 | + function parse($file) { |
|
| 259 | 259 | $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; |
| 260 | 260 | $this->authors = $this->posts = $this->term = $this->category = $this->tag = array(); |
| 261 | 261 | |
| 262 | - $xml = xml_parser_create( 'UTF-8' ); |
|
| 263 | - xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 ); |
|
| 264 | - xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 ); |
|
| 265 | - xml_set_object( $xml, $this ); |
|
| 266 | - xml_set_character_data_handler( $xml, 'cdata' ); |
|
| 267 | - xml_set_element_handler( $xml, 'tag_open', 'tag_close' ); |
|
| 268 | - |
|
| 269 | - if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) { |
|
| 270 | - $current_line = xml_get_current_line_number( $xml ); |
|
| 271 | - $current_column = xml_get_current_column_number( $xml ); |
|
| 272 | - $error_code = xml_get_error_code( $xml ); |
|
| 273 | - $error_string = xml_error_string( $error_code ); |
|
| 274 | - return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) ); |
|
| 262 | + $xml = xml_parser_create('UTF-8'); |
|
| 263 | + xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1); |
|
| 264 | + xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0); |
|
| 265 | + xml_set_object($xml, $this); |
|
| 266 | + xml_set_character_data_handler($xml, 'cdata'); |
|
| 267 | + xml_set_element_handler($xml, 'tag_open', 'tag_close'); |
|
| 268 | + |
|
| 269 | + if (!xml_parse($xml, file_get_contents($file), true)) { |
|
| 270 | + $current_line = xml_get_current_line_number($xml); |
|
| 271 | + $current_column = xml_get_current_column_number($xml); |
|
| 272 | + $error_code = xml_get_error_code($xml); |
|
| 273 | + $error_string = xml_error_string($error_code); |
|
| 274 | + return new WP_Error('XML_parse_error', 'There was an error when reading this WXR file', array($current_line, $current_column, $error_string)); |
|
| 275 | 275 | } |
| 276 | - xml_parser_free( $xml ); |
|
| 276 | + xml_parser_free($xml); |
|
| 277 | 277 | |
| 278 | - if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) |
|
| 279 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 278 | + if (!preg_match('/^\d+\.\d+$/', $this->wxr_version)) |
|
| 279 | + return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer')); |
|
| 280 | 280 | |
| 281 | 281 | return array( |
| 282 | 282 | 'authors' => $this->authors, |
@@ -289,26 +289,26 @@ discard block |
||
| 289 | 289 | ); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - function tag_open( $parse, $tag, $attr ) { |
|
| 293 | - if ( in_array( $tag, $this->wp_tags ) ) { |
|
| 294 | - $this->in_tag = substr( $tag, 3 ); |
|
| 292 | + function tag_open($parse, $tag, $attr) { |
|
| 293 | + if (in_array($tag, $this->wp_tags)) { |
|
| 294 | + $this->in_tag = substr($tag, 3); |
|
| 295 | 295 | return; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( in_array( $tag, $this->wp_sub_tags ) ) { |
|
| 299 | - $this->in_sub_tag = substr( $tag, 3 ); |
|
| 298 | + if (in_array($tag, $this->wp_sub_tags)) { |
|
| 299 | + $this->in_sub_tag = substr($tag, 3); |
|
| 300 | 300 | return; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - switch ( $tag ) { |
|
| 303 | + switch ($tag) { |
|
| 304 | 304 | case 'category': |
| 305 | - if ( isset($attr['domain'], $attr['nicename']) ) { |
|
| 305 | + if (isset($attr['domain'], $attr['nicename'])) { |
|
| 306 | 306 | $this->sub_data['domain'] = $attr['domain']; |
| 307 | 307 | $this->sub_data['slug'] = $attr['nicename']; |
| 308 | 308 | } |
| 309 | 309 | break; |
| 310 | 310 | case 'item': $this->in_post = true; |
| 311 | - case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break; |
|
| 311 | + case 'title': if ($this->in_post) $this->in_tag = 'post_title'; break; |
|
| 312 | 312 | case 'guid': $this->in_tag = 'guid'; break; |
| 313 | 313 | case 'dc:creator': $this->in_tag = 'post_author'; break; |
| 314 | 314 | case 'content:encoded': $this->in_tag = 'post_content'; break; |
@@ -320,18 +320,18 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - function cdata( $parser, $cdata ) { |
|
| 324 | - if ( ! trim( $cdata ) ) |
|
| 323 | + function cdata($parser, $cdata) { |
|
| 324 | + if (!trim($cdata)) |
|
| 325 | 325 | return; |
| 326 | 326 | |
| 327 | - $this->cdata .= trim( $cdata ); |
|
| 327 | + $this->cdata .= trim($cdata); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - function tag_close( $parser, $tag ) { |
|
| 331 | - switch ( $tag ) { |
|
| 330 | + function tag_close($parser, $tag) { |
|
| 331 | + switch ($tag) { |
|
| 332 | 332 | case 'wp:comment': |
| 333 | - unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data |
|
| 334 | - if ( ! empty( $this->sub_data ) ) |
|
| 333 | + unset($this->sub_data['key'], $this->sub_data['value']); // remove meta sub_data |
|
| 334 | + if (!empty($this->sub_data)) |
|
| 335 | 335 | $this->data['comments'][] = $this->sub_data; |
| 336 | 336 | $this->sub_data = false; |
| 337 | 337 | break; |
@@ -342,14 +342,14 @@ discard block |
||
| 342 | 342 | ); |
| 343 | 343 | break; |
| 344 | 344 | case 'category': |
| 345 | - if ( ! empty( $this->sub_data ) ) { |
|
| 345 | + if (!empty($this->sub_data)) { |
|
| 346 | 346 | $this->sub_data['name'] = $this->cdata; |
| 347 | 347 | $this->data['terms'][] = $this->sub_data; |
| 348 | 348 | } |
| 349 | 349 | $this->sub_data = false; |
| 350 | 350 | break; |
| 351 | 351 | case 'wp:postmeta': |
| 352 | - if ( ! empty( $this->sub_data ) ) |
|
| 352 | + if (!empty($this->sub_data)) |
|
| 353 | 353 | $this->data['postmeta'][] = $this->sub_data; |
| 354 | 354 | $this->sub_data = false; |
| 355 | 355 | break; |
@@ -360,12 +360,12 @@ discard block |
||
| 360 | 360 | case 'wp:category': |
| 361 | 361 | case 'wp:tag': |
| 362 | 362 | case 'wp:term': |
| 363 | - $n = substr( $tag, 3 ); |
|
| 364 | - array_push( $this->$n, $this->data ); |
|
| 363 | + $n = substr($tag, 3); |
|
| 364 | + array_push($this->$n, $this->data); |
|
| 365 | 365 | $this->data = false; |
| 366 | 366 | break; |
| 367 | 367 | case 'wp:author': |
| 368 | - if ( ! empty($this->data['author_login']) ) |
|
| 368 | + if (!empty($this->data['author_login'])) |
|
| 369 | 369 | $this->authors[$this->data['author_login']] = $this->data; |
| 370 | 370 | $this->data = false; |
| 371 | 371 | break; |
@@ -377,11 +377,11 @@ discard block |
||
| 377 | 377 | break; |
| 378 | 378 | |
| 379 | 379 | default: |
| 380 | - if ( $this->in_sub_tag ) { |
|
| 381 | - $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : ''; |
|
| 380 | + if ($this->in_sub_tag) { |
|
| 381 | + $this->sub_data[$this->in_sub_tag] = !empty($this->cdata) ? $this->cdata : ''; |
|
| 382 | 382 | $this->in_sub_tag = false; |
| 383 | - } else if ( $this->in_tag ) { |
|
| 384 | - $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : ''; |
|
| 383 | + } else if ($this->in_tag) { |
|
| 384 | + $this->data[$this->in_tag] = !empty($this->cdata) ? $this->cdata : ''; |
|
| 385 | 385 | $this->in_tag = false; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -407,66 +407,66 @@ discard block |
||
| 407 | 407 | }*/ |
| 408 | 408 | |
| 409 | 409 | function __construct() { |
| 410 | - $this->has_gzip = is_callable( 'gzopen' ); |
|
| 410 | + $this->has_gzip = is_callable('gzopen'); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - function parse( $file ) { |
|
| 413 | + function parse($file) { |
|
| 414 | 414 | $wxr_version = $in_post = false; |
| 415 | 415 | |
| 416 | - $fp = $this->fopen( $file, 'r' ); |
|
| 417 | - if ( $fp ) { |
|
| 418 | - while ( ! $this->feof( $fp ) ) { |
|
| 419 | - $importline = rtrim( $this->fgets( $fp ) ); |
|
| 416 | + $fp = $this->fopen($file, 'r'); |
|
| 417 | + if ($fp) { |
|
| 418 | + while (!$this->feof($fp)) { |
|
| 419 | + $importline = rtrim($this->fgets($fp)); |
|
| 420 | 420 | |
| 421 | - if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) ) |
|
| 421 | + if (!$wxr_version && preg_match('|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version)) |
|
| 422 | 422 | $wxr_version = $version[1]; |
| 423 | 423 | |
| 424 | - if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) { |
|
| 425 | - preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url ); |
|
| 424 | + if (false !== strpos($importline, '<wp:base_site_url>')) { |
|
| 425 | + preg_match('|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url); |
|
| 426 | 426 | $this->base_url = $url[1]; |
| 427 | 427 | continue; |
| 428 | 428 | } |
| 429 | - if ( false !== strpos( $importline, '<wp:category>' ) ) { |
|
| 430 | - preg_match( '|<wp:category>(.*?)</wp:category>|is', $importline, $category ); |
|
| 431 | - $this->categories[] = $this->process_category( $category[1] ); |
|
| 429 | + if (false !== strpos($importline, '<wp:category>')) { |
|
| 430 | + preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); |
|
| 431 | + $this->categories[] = $this->process_category($category[1]); |
|
| 432 | 432 | continue; |
| 433 | 433 | } |
| 434 | - if ( false !== strpos( $importline, '<wp:tag>' ) ) { |
|
| 435 | - preg_match( '|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag ); |
|
| 436 | - $this->tags[] = $this->process_tag( $tag[1] ); |
|
| 434 | + if (false !== strpos($importline, '<wp:tag>')) { |
|
| 435 | + preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag); |
|
| 436 | + $this->tags[] = $this->process_tag($tag[1]); |
|
| 437 | 437 | continue; |
| 438 | 438 | } |
| 439 | - if ( false !== strpos( $importline, '<wp:term>' ) ) { |
|
| 440 | - preg_match( '|<wp:term>(.*?)</wp:term>|is', $importline, $term ); |
|
| 441 | - $this->terms[] = $this->process_term( $term[1] ); |
|
| 439 | + if (false !== strpos($importline, '<wp:term>')) { |
|
| 440 | + preg_match('|<wp:term>(.*?)</wp:term>|is', $importline, $term); |
|
| 441 | + $this->terms[] = $this->process_term($term[1]); |
|
| 442 | 442 | continue; |
| 443 | 443 | } |
| 444 | - if ( false !== strpos( $importline, '<wp:author>' ) ) { |
|
| 445 | - preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author ); |
|
| 446 | - $a = $this->process_author( $author[1] ); |
|
| 444 | + if (false !== strpos($importline, '<wp:author>')) { |
|
| 445 | + preg_match('|<wp:author>(.*?)</wp:author>|is', $importline, $author); |
|
| 446 | + $a = $this->process_author($author[1]); |
|
| 447 | 447 | $this->authors[$a['author_login']] = $a; |
| 448 | 448 | continue; |
| 449 | 449 | } |
| 450 | - if ( false !== strpos( $importline, '<item>' ) ) { |
|
| 450 | + if (false !== strpos($importline, '<item>')) { |
|
| 451 | 451 | $post = ''; |
| 452 | 452 | $in_post = true; |
| 453 | 453 | continue; |
| 454 | 454 | } |
| 455 | - if ( false !== strpos( $importline, '</item>' ) ) { |
|
| 455 | + if (false !== strpos($importline, '</item>')) { |
|
| 456 | 456 | $in_post = false; |
| 457 | - $this->posts[] = $this->process_post( $post ); |
|
| 457 | + $this->posts[] = $this->process_post($post); |
|
| 458 | 458 | continue; |
| 459 | 459 | } |
| 460 | - if ( $in_post ) { |
|
| 461 | - $post .= $importline . "\n"; |
|
| 460 | + if ($in_post) { |
|
| 461 | + $post .= $importline."\n"; |
|
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | $this->fclose($fp); |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if ( ! $wxr_version ) |
|
| 469 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 468 | + if (!$wxr_version) |
|
| 469 | + return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer')); |
|
| 470 | 470 | |
| 471 | 471 | return array( |
| 472 | 472 | 'authors' => $this->authors, |
@@ -479,17 +479,17 @@ discard block |
||
| 479 | 479 | ); |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - function get_tag( $string, $tag ) { |
|
| 483 | - preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return ); |
|
| 484 | - if ( isset( $return[1] ) ) { |
|
| 485 | - if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) { |
|
| 486 | - if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) { |
|
| 487 | - preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches ); |
|
| 482 | + function get_tag($string, $tag) { |
|
| 483 | + preg_match("|<$tag.*?>(.*?)</$tag>|is", $string, $return); |
|
| 484 | + if (isset($return[1])) { |
|
| 485 | + if (substr($return[1], 0, 9) == '<![CDATA[') { |
|
| 486 | + if (strpos($return[1], ']]]]><![CDATA[>') !== false) { |
|
| 487 | + preg_match_all('|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches); |
|
| 488 | 488 | $return = ''; |
| 489 | - foreach( $matches[1] as $match ) |
|
| 489 | + foreach ($matches[1] as $match) |
|
| 490 | 490 | $return .= $match; |
| 491 | 491 | } else { |
| 492 | - $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] ); |
|
| 492 | + $return = preg_replace('|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1]); |
|
| 493 | 493 | } |
| 494 | 494 | } else { |
| 495 | 495 | $return = $return[1]; |
@@ -500,166 +500,166 @@ discard block |
||
| 500 | 500 | return $return; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - function process_category( $c ) { |
|
| 503 | + function process_category($c) { |
|
| 504 | 504 | return array( |
| 505 | - 'term_id' => $this->get_tag( $c, 'wp:term_id' ), |
|
| 506 | - 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ), |
|
| 507 | - 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ), |
|
| 508 | - 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ), |
|
| 509 | - 'category_description' => $this->get_tag( $c, 'wp:category_description' ), |
|
| 505 | + 'term_id' => $this->get_tag($c, 'wp:term_id'), |
|
| 506 | + 'cat_name' => $this->get_tag($c, 'wp:cat_name'), |
|
| 507 | + 'category_nicename' => $this->get_tag($c, 'wp:category_nicename'), |
|
| 508 | + 'category_parent' => $this->get_tag($c, 'wp:category_parent'), |
|
| 509 | + 'category_description' => $this->get_tag($c, 'wp:category_description'), |
|
| 510 | 510 | ); |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - function process_tag( $t ) { |
|
| 513 | + function process_tag($t) { |
|
| 514 | 514 | return array( |
| 515 | - 'term_id' => $this->get_tag( $t, 'wp:term_id' ), |
|
| 516 | - 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ), |
|
| 517 | - 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ), |
|
| 518 | - 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ), |
|
| 515 | + 'term_id' => $this->get_tag($t, 'wp:term_id'), |
|
| 516 | + 'tag_name' => $this->get_tag($t, 'wp:tag_name'), |
|
| 517 | + 'tag_slug' => $this->get_tag($t, 'wp:tag_slug'), |
|
| 518 | + 'tag_description' => $this->get_tag($t, 'wp:tag_description'), |
|
| 519 | 519 | ); |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - function process_term( $t ) { |
|
| 522 | + function process_term($t) { |
|
| 523 | 523 | return array( |
| 524 | - 'term_id' => $this->get_tag( $t, 'wp:term_id' ), |
|
| 525 | - 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ), |
|
| 526 | - 'slug' => $this->get_tag( $t, 'wp:term_slug' ), |
|
| 527 | - 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ), |
|
| 528 | - 'term_name' => $this->get_tag( $t, 'wp:term_name' ), |
|
| 529 | - 'term_description' => $this->get_tag( $t, 'wp:term_description' ), |
|
| 524 | + 'term_id' => $this->get_tag($t, 'wp:term_id'), |
|
| 525 | + 'term_taxonomy' => $this->get_tag($t, 'wp:term_taxonomy'), |
|
| 526 | + 'slug' => $this->get_tag($t, 'wp:term_slug'), |
|
| 527 | + 'term_parent' => $this->get_tag($t, 'wp:term_parent'), |
|
| 528 | + 'term_name' => $this->get_tag($t, 'wp:term_name'), |
|
| 529 | + 'term_description' => $this->get_tag($t, 'wp:term_description'), |
|
| 530 | 530 | ); |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - function process_author( $a ) { |
|
| 533 | + function process_author($a) { |
|
| 534 | 534 | return array( |
| 535 | - 'author_id' => $this->get_tag( $a, 'wp:author_id' ), |
|
| 536 | - 'author_login' => $this->get_tag( $a, 'wp:author_login' ), |
|
| 537 | - 'author_email' => $this->get_tag( $a, 'wp:author_email' ), |
|
| 538 | - 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ), |
|
| 539 | - 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ), |
|
| 540 | - 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ), |
|
| 535 | + 'author_id' => $this->get_tag($a, 'wp:author_id'), |
|
| 536 | + 'author_login' => $this->get_tag($a, 'wp:author_login'), |
|
| 537 | + 'author_email' => $this->get_tag($a, 'wp:author_email'), |
|
| 538 | + 'author_display_name' => $this->get_tag($a, 'wp:author_display_name'), |
|
| 539 | + 'author_first_name' => $this->get_tag($a, 'wp:author_first_name'), |
|
| 540 | + 'author_last_name' => $this->get_tag($a, 'wp:author_last_name'), |
|
| 541 | 541 | ); |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - function process_post( $post ) { |
|
| 545 | - $post_id = $this->get_tag( $post, 'wp:post_id' ); |
|
| 546 | - $post_title = $this->get_tag( $post, 'title' ); |
|
| 547 | - $post_date = $this->get_tag( $post, 'wp:post_date' ); |
|
| 548 | - $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' ); |
|
| 549 | - $comment_status = $this->get_tag( $post, 'wp:comment_status' ); |
|
| 550 | - $ping_status = $this->get_tag( $post, 'wp:ping_status' ); |
|
| 551 | - $status = $this->get_tag( $post, 'wp:status' ); |
|
| 552 | - $post_name = $this->get_tag( $post, 'wp:post_name' ); |
|
| 553 | - $post_parent = $this->get_tag( $post, 'wp:post_parent' ); |
|
| 554 | - $menu_order = $this->get_tag( $post, 'wp:menu_order' ); |
|
| 555 | - $post_type = $this->get_tag( $post, 'wp:post_type' ); |
|
| 556 | - $post_password = $this->get_tag( $post, 'wp:post_password' ); |
|
| 557 | - $is_sticky = $this->get_tag( $post, 'wp:is_sticky' ); |
|
| 558 | - $guid = $this->get_tag( $post, 'guid' ); |
|
| 559 | - $post_author = $this->get_tag( $post, 'dc:creator' ); |
|
| 560 | - |
|
| 561 | - $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' ); |
|
| 562 | - $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt ); |
|
| 563 | - $post_excerpt = str_replace( '<br>', '<br />', $post_excerpt ); |
|
| 564 | - $post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt ); |
|
| 565 | - |
|
| 566 | - $post_content = $this->get_tag( $post, 'content:encoded' ); |
|
| 567 | - $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content ); |
|
| 568 | - $post_content = str_replace( '<br>', '<br />', $post_content ); |
|
| 569 | - $post_content = str_replace( '<hr>', '<hr />', $post_content ); |
|
| 570 | - |
|
| 571 | - $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', |
|
| 544 | + function process_post($post) { |
|
| 545 | + $post_id = $this->get_tag($post, 'wp:post_id'); |
|
| 546 | + $post_title = $this->get_tag($post, 'title'); |
|
| 547 | + $post_date = $this->get_tag($post, 'wp:post_date'); |
|
| 548 | + $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt'); |
|
| 549 | + $comment_status = $this->get_tag($post, 'wp:comment_status'); |
|
| 550 | + $ping_status = $this->get_tag($post, 'wp:ping_status'); |
|
| 551 | + $status = $this->get_tag($post, 'wp:status'); |
|
| 552 | + $post_name = $this->get_tag($post, 'wp:post_name'); |
|
| 553 | + $post_parent = $this->get_tag($post, 'wp:post_parent'); |
|
| 554 | + $menu_order = $this->get_tag($post, 'wp:menu_order'); |
|
| 555 | + $post_type = $this->get_tag($post, 'wp:post_type'); |
|
| 556 | + $post_password = $this->get_tag($post, 'wp:post_password'); |
|
| 557 | + $is_sticky = $this->get_tag($post, 'wp:is_sticky'); |
|
| 558 | + $guid = $this->get_tag($post, 'guid'); |
|
| 559 | + $post_author = $this->get_tag($post, 'dc:creator'); |
|
| 560 | + |
|
| 561 | + $post_excerpt = $this->get_tag($post, 'excerpt:encoded'); |
|
| 562 | + $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_excerpt); |
|
| 563 | + $post_excerpt = str_replace('<br>', '<br />', $post_excerpt); |
|
| 564 | + $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt); |
|
| 565 | + |
|
| 566 | + $post_content = $this->get_tag($post, 'content:encoded'); |
|
| 567 | + $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content); |
|
| 568 | + $post_content = str_replace('<br>', '<br />', $post_content); |
|
| 569 | + $post_content = str_replace('<hr>', '<hr />', $post_content); |
|
| 570 | + |
|
| 571 | + $postdata = compact('post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', |
|
| 572 | 572 | 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', |
| 573 | 573 | 'menu_order', 'post_type', 'post_password', 'is_sticky' |
| 574 | 574 | ); |
| 575 | 575 | |
| 576 | - $attachment_url = $this->get_tag( $post, 'wp:attachment_url' ); |
|
| 577 | - if ( $attachment_url ) |
|
| 576 | + $attachment_url = $this->get_tag($post, 'wp:attachment_url'); |
|
| 577 | + if ($attachment_url) |
|
| 578 | 578 | $postdata['attachment_url'] = $attachment_url; |
| 579 | 579 | |
| 580 | - preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER ); |
|
| 581 | - foreach ( $terms as $t ) { |
|
| 580 | + preg_match_all('|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER); |
|
| 581 | + foreach ($terms as $t) { |
|
| 582 | 582 | $post_terms[] = array( |
| 583 | 583 | 'slug' => $t[2], |
| 584 | 584 | 'domain' => $t[1], |
| 585 | - 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ), |
|
| 585 | + 'name' => str_replace(array('<![CDATA[', ']]>'), '', $t[3]), |
|
| 586 | 586 | ); |
| 587 | 587 | } |
| 588 | - if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms; |
|
| 588 | + if (!empty($post_terms)) $postdata['terms'] = $post_terms; |
|
| 589 | 589 | |
| 590 | - preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments ); |
|
| 590 | + preg_match_all('|<wp:comment>(.+?)</wp:comment>|is', $post, $comments); |
|
| 591 | 591 | $comments = $comments[1]; |
| 592 | - if ( $comments ) { |
|
| 593 | - foreach ( $comments as $comment ) { |
|
| 594 | - preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta ); |
|
| 592 | + if ($comments) { |
|
| 593 | + foreach ($comments as $comment) { |
|
| 594 | + preg_match_all('|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta); |
|
| 595 | 595 | $commentmeta = $commentmeta[1]; |
| 596 | 596 | $c_meta = array(); |
| 597 | - foreach ( $commentmeta as $m ) { |
|
| 597 | + foreach ($commentmeta as $m) { |
|
| 598 | 598 | $c_meta[] = array( |
| 599 | - 'key' => $this->get_tag( $m, 'wp:meta_key' ), |
|
| 600 | - 'value' => $this->get_tag( $m, 'wp:meta_value' ), |
|
| 599 | + 'key' => $this->get_tag($m, 'wp:meta_key'), |
|
| 600 | + 'value' => $this->get_tag($m, 'wp:meta_value'), |
|
| 601 | 601 | ); |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | $post_comments[] = array( |
| 605 | - 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ), |
|
| 606 | - 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ), |
|
| 607 | - 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ), |
|
| 608 | - 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ), |
|
| 609 | - 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ), |
|
| 610 | - 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ), |
|
| 611 | - 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ), |
|
| 612 | - 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ), |
|
| 613 | - 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ), |
|
| 614 | - 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ), |
|
| 615 | - 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ), |
|
| 616 | - 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ), |
|
| 605 | + 'comment_id' => $this->get_tag($comment, 'wp:comment_id'), |
|
| 606 | + 'comment_author' => $this->get_tag($comment, 'wp:comment_author'), |
|
| 607 | + 'comment_author_email' => $this->get_tag($comment, 'wp:comment_author_email'), |
|
| 608 | + 'comment_author_IP' => $this->get_tag($comment, 'wp:comment_author_IP'), |
|
| 609 | + 'comment_author_url' => $this->get_tag($comment, 'wp:comment_author_url'), |
|
| 610 | + 'comment_date' => $this->get_tag($comment, 'wp:comment_date'), |
|
| 611 | + 'comment_date_gmt' => $this->get_tag($comment, 'wp:comment_date_gmt'), |
|
| 612 | + 'comment_content' => $this->get_tag($comment, 'wp:comment_content'), |
|
| 613 | + 'comment_approved' => $this->get_tag($comment, 'wp:comment_approved'), |
|
| 614 | + 'comment_type' => $this->get_tag($comment, 'wp:comment_type'), |
|
| 615 | + 'comment_parent' => $this->get_tag($comment, 'wp:comment_parent'), |
|
| 616 | + 'comment_user_id' => $this->get_tag($comment, 'wp:comment_user_id'), |
|
| 617 | 617 | 'commentmeta' => $c_meta, |
| 618 | 618 | ); |
| 619 | 619 | } |
| 620 | 620 | } |
| 621 | - if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments; |
|
| 621 | + if (!empty($post_comments)) $postdata['comments'] = $post_comments; |
|
| 622 | 622 | |
| 623 | - preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta ); |
|
| 623 | + preg_match_all('|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta); |
|
| 624 | 624 | $postmeta = $postmeta[1]; |
| 625 | - if ( $postmeta ) { |
|
| 626 | - foreach ( $postmeta as $p ) { |
|
| 625 | + if ($postmeta) { |
|
| 626 | + foreach ($postmeta as $p) { |
|
| 627 | 627 | $post_postmeta[] = array( |
| 628 | - 'key' => $this->get_tag( $p, 'wp:meta_key' ), |
|
| 629 | - 'value' => $this->get_tag( $p, 'wp:meta_value' ), |
|
| 628 | + 'key' => $this->get_tag($p, 'wp:meta_key'), |
|
| 629 | + 'value' => $this->get_tag($p, 'wp:meta_value'), |
|
| 630 | 630 | ); |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | - if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta; |
|
| 633 | + if (!empty($post_postmeta)) $postdata['postmeta'] = $post_postmeta; |
|
| 634 | 634 | |
| 635 | 635 | return $postdata; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - function _normalize_tag( $matches ) { |
|
| 639 | - return '<' . strtolower( $matches[1] ); |
|
| 638 | + function _normalize_tag($matches) { |
|
| 639 | + return '<'.strtolower($matches[1]); |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - function fopen( $filename, $mode = 'r' ) { |
|
| 643 | - if ( $this->has_gzip ) |
|
| 644 | - return gzopen( $filename, $mode ); |
|
| 645 | - return fopen( $filename, $mode ); |
|
| 642 | + function fopen($filename, $mode = 'r') { |
|
| 643 | + if ($this->has_gzip) |
|
| 644 | + return gzopen($filename, $mode); |
|
| 645 | + return fopen($filename, $mode); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - function feof( $fp ) { |
|
| 649 | - if ( $this->has_gzip ) |
|
| 650 | - return gzeof( $fp ); |
|
| 651 | - return feof( $fp ); |
|
| 648 | + function feof($fp) { |
|
| 649 | + if ($this->has_gzip) |
|
| 650 | + return gzeof($fp); |
|
| 651 | + return feof($fp); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - function fgets( $fp, $len = 8192 ) { |
|
| 655 | - if ( $this->has_gzip ) |
|
| 656 | - return gzgets( $fp, $len ); |
|
| 657 | - return fgets( $fp, $len ); |
|
| 654 | + function fgets($fp, $len = 8192) { |
|
| 655 | + if ($this->has_gzip) |
|
| 656 | + return gzgets($fp, $len); |
|
| 657 | + return fgets($fp, $len); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - function fclose( $fp ) { |
|
| 661 | - if ( $this->has_gzip ) |
|
| 662 | - return gzclose( $fp ); |
|
| 663 | - return fclose( $fp ); |
|
| 660 | + function fclose($fp) { |
|
| 661 | + if ($this->has_gzip) |
|
| 662 | + return gzclose($fp); |
|
| 663 | + return fclose($fp); |
|
| 664 | 664 | } |
| 665 | 665 | } |
@@ -17,23 +17,26 @@ discard block |
||
| 17 | 17 | $result = $parser->parse( $file ); |
| 18 | 18 | |
| 19 | 19 | // If SimpleXML succeeds or this is an invalid WXR file then return the results |
| 20 | - if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) |
|
| 21 | - return $result; |
|
| 20 | + if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) { |
|
| 21 | + return $result; |
|
| 22 | + } |
|
| 22 | 23 | } else if ( extension_loaded( 'xml' ) ) { |
| 23 | 24 | $parser = new WXR_Parser_XML; |
| 24 | 25 | $result = $parser->parse( $file ); |
| 25 | 26 | |
| 26 | 27 | // If XMLParser succeeds or this is an invalid WXR file then return the results |
| 27 | - if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) |
|
| 28 | - return $result; |
|
| 28 | + if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) { |
|
| 29 | + return $result; |
|
| 30 | + } |
|
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | // We have a malformed XML file, so display the error and fallthrough to regex |
| 32 | 34 | if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) { |
| 33 | 35 | echo '<pre>'; |
| 34 | 36 | if ( 'SimpleXML_parse_error' == $result->get_error_code() ) { |
| 35 | - foreach ( $result->get_error_data() as $error ) |
|
| 36 | - echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n"; |
|
| 37 | + foreach ( $result->get_error_data() as $error ) { |
|
| 38 | + echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n"; |
|
| 39 | + } |
|
| 37 | 40 | } else if ( 'XML_parse_error' == $result->get_error_code() ) { |
| 38 | 41 | $error = $result->get_error_data(); |
| 39 | 42 | echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] ); |
@@ -76,26 +79,31 @@ discard block |
||
| 76 | 79 | unset( $dom ); |
| 77 | 80 | |
| 78 | 81 | // halt if loading produces an error |
| 79 | - if ( ! $xml ) |
|
| 80 | - return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); |
|
| 82 | + if ( ! $xml ) { |
|
| 83 | + return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); |
|
| 84 | + } |
|
| 81 | 85 | |
| 82 | 86 | $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version'); |
| 83 | - if ( ! $wxr_version ) |
|
| 84 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 87 | + if ( ! $wxr_version ) { |
|
| 88 | + return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 89 | + } |
|
| 85 | 90 | |
| 86 | 91 | $wxr_version = (string) trim( $wxr_version[0] ); |
| 87 | 92 | // confirm that we are dealing with the correct file format |
| 88 | - if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) |
|
| 89 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 93 | + if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) { |
|
| 94 | + return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 95 | + } |
|
| 90 | 96 | |
| 91 | 97 | $base_url = $xml->xpath('/rss/channel/wp:base_site_url'); |
| 92 | 98 | $base_url = isset($base_url[0]) ? (string) trim( $base_url[0] ) : ''; // Modified by GravityView: Check if base_url exists; the GV import files may exclude them. |
| 93 | 99 | |
| 94 | 100 | $namespaces = $xml->getDocNamespaces(); |
| 95 | - if ( ! isset( $namespaces['wp'] ) ) |
|
| 96 | - $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 97 | - if ( ! isset( $namespaces['excerpt'] ) ) |
|
| 98 | - $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 101 | + if ( ! isset( $namespaces['wp'] ) ) { |
|
| 102 | + $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 103 | + } |
|
| 104 | + if ( ! isset( $namespaces['excerpt'] ) ) { |
|
| 105 | + $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 106 | + } |
|
| 99 | 107 | |
| 100 | 108 | // grab authors |
| 101 | 109 | foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) { |
@@ -174,17 +182,19 @@ discard block |
||
| 174 | 182 | $post['post_password'] = (string) $wp->post_password; |
| 175 | 183 | $post['is_sticky'] = (int) $wp->is_sticky; |
| 176 | 184 | |
| 177 | - if ( isset($wp->attachment_url) ) |
|
| 178 | - $post['attachment_url'] = (string) $wp->attachment_url; |
|
| 185 | + if ( isset($wp->attachment_url) ) { |
|
| 186 | + $post['attachment_url'] = (string) $wp->attachment_url; |
|
| 187 | + } |
|
| 179 | 188 | |
| 180 | 189 | foreach ( $item->category as $c ) { |
| 181 | 190 | $att = $c->attributes(); |
| 182 | - if ( isset( $att['nicename'] ) ) |
|
| 183 | - $post['terms'][] = array( |
|
| 191 | + if ( isset( $att['nicename'] ) ) { |
|
| 192 | + $post['terms'][] = array( |
|
| 184 | 193 | 'name' => (string) $c, |
| 185 | 194 | 'slug' => (string) $att['nicename'], |
| 186 | 195 | 'domain' => (string) $att['domain'] |
| 187 | 196 | ); |
| 197 | + } |
|
| 188 | 198 | } |
| 189 | 199 | |
| 190 | 200 | foreach ( $wp->postmeta as $meta ) { |
@@ -275,8 +285,9 @@ discard block |
||
| 275 | 285 | } |
| 276 | 286 | xml_parser_free( $xml ); |
| 277 | 287 | |
| 278 | - if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) |
|
| 279 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 288 | + if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) { |
|
| 289 | + return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 290 | + } |
|
| 280 | 291 | |
| 281 | 292 | return array( |
| 282 | 293 | 'authors' => $this->authors, |
@@ -308,7 +319,10 @@ discard block |
||
| 308 | 319 | } |
| 309 | 320 | break; |
| 310 | 321 | case 'item': $this->in_post = true; |
| 311 | - case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break; |
|
| 322 | + case 'title': if ( $this->in_post ) { |
|
| 323 | + $this->in_tag = 'post_title'; |
|
| 324 | + } |
|
| 325 | + break; |
|
| 312 | 326 | case 'guid': $this->in_tag = 'guid'; break; |
| 313 | 327 | case 'dc:creator': $this->in_tag = 'post_author'; break; |
| 314 | 328 | case 'content:encoded': $this->in_tag = 'post_content'; break; |
@@ -321,8 +335,9 @@ discard block |
||
| 321 | 335 | } |
| 322 | 336 | |
| 323 | 337 | function cdata( $parser, $cdata ) { |
| 324 | - if ( ! trim( $cdata ) ) |
|
| 325 | - return; |
|
| 338 | + if ( ! trim( $cdata ) ) { |
|
| 339 | + return; |
|
| 340 | + } |
|
| 326 | 341 | |
| 327 | 342 | $this->cdata .= trim( $cdata ); |
| 328 | 343 | } |
@@ -331,8 +346,9 @@ discard block |
||
| 331 | 346 | switch ( $tag ) { |
| 332 | 347 | case 'wp:comment': |
| 333 | 348 | unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data |
| 334 | - if ( ! empty( $this->sub_data ) ) |
|
| 335 | - $this->data['comments'][] = $this->sub_data; |
|
| 349 | + if ( ! empty( $this->sub_data ) ) { |
|
| 350 | + $this->data['comments'][] = $this->sub_data; |
|
| 351 | + } |
|
| 336 | 352 | $this->sub_data = false; |
| 337 | 353 | break; |
| 338 | 354 | case 'wp:commentmeta': |
@@ -349,8 +365,9 @@ discard block |
||
| 349 | 365 | $this->sub_data = false; |
| 350 | 366 | break; |
| 351 | 367 | case 'wp:postmeta': |
| 352 | - if ( ! empty( $this->sub_data ) ) |
|
| 353 | - $this->data['postmeta'][] = $this->sub_data; |
|
| 368 | + if ( ! empty( $this->sub_data ) ) { |
|
| 369 | + $this->data['postmeta'][] = $this->sub_data; |
|
| 370 | + } |
|
| 354 | 371 | $this->sub_data = false; |
| 355 | 372 | break; |
| 356 | 373 | case 'item': |
@@ -365,8 +382,9 @@ discard block |
||
| 365 | 382 | $this->data = false; |
| 366 | 383 | break; |
| 367 | 384 | case 'wp:author': |
| 368 | - if ( ! empty($this->data['author_login']) ) |
|
| 369 | - $this->authors[$this->data['author_login']] = $this->data; |
|
| 385 | + if ( ! empty($this->data['author_login']) ) { |
|
| 386 | + $this->authors[$this->data['author_login']] = $this->data; |
|
| 387 | + } |
|
| 370 | 388 | $this->data = false; |
| 371 | 389 | break; |
| 372 | 390 | case 'wp:base_site_url': |
@@ -418,8 +436,9 @@ discard block |
||
| 418 | 436 | while ( ! $this->feof( $fp ) ) { |
| 419 | 437 | $importline = rtrim( $this->fgets( $fp ) ); |
| 420 | 438 | |
| 421 | - if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) ) |
|
| 422 | - $wxr_version = $version[1]; |
|
| 439 | + if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) ) { |
|
| 440 | + $wxr_version = $version[1]; |
|
| 441 | + } |
|
| 423 | 442 | |
| 424 | 443 | if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) { |
| 425 | 444 | preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url ); |
@@ -465,8 +484,9 @@ discard block |
||
| 465 | 484 | $this->fclose($fp); |
| 466 | 485 | } |
| 467 | 486 | |
| 468 | - if ( ! $wxr_version ) |
|
| 469 | - return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 487 | + if ( ! $wxr_version ) { |
|
| 488 | + return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); |
|
| 489 | + } |
|
| 470 | 490 | |
| 471 | 491 | return array( |
| 472 | 492 | 'authors' => $this->authors, |
@@ -486,8 +506,9 @@ discard block |
||
| 486 | 506 | if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) { |
| 487 | 507 | preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches ); |
| 488 | 508 | $return = ''; |
| 489 | - foreach( $matches[1] as $match ) |
|
| 490 | - $return .= $match; |
|
| 509 | + foreach( $matches[1] as $match ) { |
|
| 510 | + $return .= $match; |
|
| 511 | + } |
|
| 491 | 512 | } else { |
| 492 | 513 | $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] ); |
| 493 | 514 | } |
@@ -574,8 +595,9 @@ discard block |
||
| 574 | 595 | ); |
| 575 | 596 | |
| 576 | 597 | $attachment_url = $this->get_tag( $post, 'wp:attachment_url' ); |
| 577 | - if ( $attachment_url ) |
|
| 578 | - $postdata['attachment_url'] = $attachment_url; |
|
| 598 | + if ( $attachment_url ) { |
|
| 599 | + $postdata['attachment_url'] = $attachment_url; |
|
| 600 | + } |
|
| 579 | 601 | |
| 580 | 602 | preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER ); |
| 581 | 603 | foreach ( $terms as $t ) { |
@@ -585,7 +607,9 @@ discard block |
||
| 585 | 607 | 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ), |
| 586 | 608 | ); |
| 587 | 609 | } |
| 588 | - if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms; |
|
| 610 | + if ( ! empty( $post_terms ) ) { |
|
| 611 | + $postdata['terms'] = $post_terms; |
|
| 612 | + } |
|
| 589 | 613 | |
| 590 | 614 | preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments ); |
| 591 | 615 | $comments = $comments[1]; |
@@ -618,7 +642,9 @@ discard block |
||
| 618 | 642 | ); |
| 619 | 643 | } |
| 620 | 644 | } |
| 621 | - if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments; |
|
| 645 | + if ( ! empty( $post_comments ) ) { |
|
| 646 | + $postdata['comments'] = $post_comments; |
|
| 647 | + } |
|
| 622 | 648 | |
| 623 | 649 | preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta ); |
| 624 | 650 | $postmeta = $postmeta[1]; |
@@ -630,7 +656,9 @@ discard block |
||
| 630 | 656 | ); |
| 631 | 657 | } |
| 632 | 658 | } |
| 633 | - if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta; |
|
| 659 | + if ( ! empty( $post_postmeta ) ) { |
|
| 660 | + $postdata['postmeta'] = $post_postmeta; |
|
| 661 | + } |
|
| 634 | 662 | |
| 635 | 663 | return $postdata; |
| 636 | 664 | } |
@@ -640,26 +668,30 @@ discard block |
||
| 640 | 668 | } |
| 641 | 669 | |
| 642 | 670 | function fopen( $filename, $mode = 'r' ) { |
| 643 | - if ( $this->has_gzip ) |
|
| 644 | - return gzopen( $filename, $mode ); |
|
| 671 | + if ( $this->has_gzip ) { |
|
| 672 | + return gzopen( $filename, $mode ); |
|
| 673 | + } |
|
| 645 | 674 | return fopen( $filename, $mode ); |
| 646 | 675 | } |
| 647 | 676 | |
| 648 | 677 | function feof( $fp ) { |
| 649 | - if ( $this->has_gzip ) |
|
| 650 | - return gzeof( $fp ); |
|
| 678 | + if ( $this->has_gzip ) { |
|
| 679 | + return gzeof( $fp ); |
|
| 680 | + } |
|
| 651 | 681 | return feof( $fp ); |
| 652 | 682 | } |
| 653 | 683 | |
| 654 | 684 | function fgets( $fp, $len = 8192 ) { |
| 655 | - if ( $this->has_gzip ) |
|
| 656 | - return gzgets( $fp, $len ); |
|
| 685 | + if ( $this->has_gzip ) { |
|
| 686 | + return gzgets( $fp, $len ); |
|
| 687 | + } |
|
| 657 | 688 | return fgets( $fp, $len ); |
| 658 | 689 | } |
| 659 | 690 | |
| 660 | 691 | function fclose( $fp ) { |
| 661 | - if ( $this->has_gzip ) |
|
| 662 | - return gzclose( $fp ); |
|
| 692 | + if ( $this->has_gzip ) { |
|
| 693 | + return gzclose( $fp ); |
|
| 694 | + } |
|
| 663 | 695 | return fclose( $fp ); |
| 664 | 696 | } |
| 665 | 697 | } |
@@ -169,7 +169,6 @@ |
||
| 169 | 169 | * |
| 170 | 170 | * @since 1.15.2 |
| 171 | 171 | * |
| 172 | - * @param array $handles Array of meta keys to check for existence of shortcodes |
|
| 173 | 172 | * @param int $post_id The ID being checked by GravityView |
| 174 | 173 | * |
| 175 | 174 | * @return array Meta key array, merged with existing meta keys |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles, as well as |
|
| 4 | - * add post meta keys for GravityView to parse when checking for the existence of shortcodes in content. |
|
| 5 | - * |
|
| 6 | - * @file abstract-gravityview-plugin-and-theme-hooks.php |
|
| 7 | - * @package GravityView |
|
| 8 | - * @license GPL2+ |
|
| 9 | - * @author Katz Web Services, Inc. |
|
| 10 | - * @link http://gravityview.co |
|
| 11 | - * @copyright Copyright 2015, Katz Web Services, Inc. |
|
| 12 | - * |
|
| 13 | - * @since 1.15.2 |
|
| 14 | - */ |
|
| 3 | + * Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles, as well as |
|
| 4 | + * add post meta keys for GravityView to parse when checking for the existence of shortcodes in content. |
|
| 5 | + * |
|
| 6 | + * @file abstract-gravityview-plugin-and-theme-hooks.php |
|
| 7 | + * @package GravityView |
|
| 8 | + * @license GPL2+ |
|
| 9 | + * @author Katz Web Services, Inc. |
|
| 10 | + * @link http://gravityview.co |
|
| 11 | + * @copyright Copyright 2015, Katz Web Services, Inc. |
|
| 12 | + * |
|
| 13 | + * @since 1.15.2 |
|
| 14 | + */ |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles, as well as |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | 91 | private function maybe_add_hooks() { |
| 92 | - $class_exists = ! $this->class_name || ( $this->class_name && class_exists( $this->class_name ) ); |
|
| 93 | - $function_exists = ! $this->function_name || ( $this->function_name && function_exists( $this->function_name ) ); |
|
| 94 | - $constant_defined = ! $this->constant_name || ( $this->constant_name && defined( $this->constant_name ) ); |
|
| 92 | + $class_exists = !$this->class_name || ($this->class_name && class_exists($this->class_name)); |
|
| 93 | + $function_exists = !$this->function_name || ($this->function_name && function_exists($this->function_name)); |
|
| 94 | + $constant_defined = !$this->constant_name || ($this->constant_name && defined($this->constant_name)); |
|
| 95 | 95 | |
| 96 | - if( $class_exists || $function_exists || $constant_defined ) { |
|
| 96 | + if ($class_exists || $function_exists || $constant_defined) { |
|
| 97 | 97 | $this->add_hooks(); |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -104,20 +104,20 @@ discard block |
||
| 104 | 104 | * @return void |
| 105 | 105 | */ |
| 106 | 106 | protected function add_hooks() { |
| 107 | - if( $this->content_meta_keys ) { |
|
| 108 | - add_filter( 'gravityview/data/parse/meta_keys', array( $this, 'merge_content_meta_keys' ), 10, 2 ); |
|
| 107 | + if ($this->content_meta_keys) { |
|
| 108 | + add_filter('gravityview/data/parse/meta_keys', array($this, 'merge_content_meta_keys'), 10, 2); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if( $this->script_handles ) { |
|
| 112 | - add_filter( 'gravityview_noconflict_scripts', array( $this, 'merge_noconflict_scripts' ) ); |
|
| 111 | + if ($this->script_handles) { |
|
| 112 | + add_filter('gravityview_noconflict_scripts', array($this, 'merge_noconflict_scripts')); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if( $this->style_handles ) { |
|
| 116 | - add_filter( 'gravityview_noconflict_styles', array( $this, 'merge_noconflict_styles' ) ); |
|
| 115 | + if ($this->style_handles) { |
|
| 116 | + add_filter('gravityview_noconflict_styles', array($this, 'merge_noconflict_styles')); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if( $this->post_type_support ) { |
|
| 120 | - add_filter( 'gravityview_post_type_support', array( $this, 'merge_post_type_support' ), 10, 2 ); |
|
| 119 | + if ($this->post_type_support) { |
|
| 120 | + add_filter('gravityview_post_type_support', array($this, 'merge_post_type_support'), 10, 2); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return array Array of features associated with a functional area of the edit screen, merged with existing values |
| 133 | 133 | */ |
| 134 | - public function merge_post_type_support( $supports = array(), $is_hierarchical = false ) { |
|
| 135 | - $supports = array_merge( $this->post_type_support, $supports ); |
|
| 134 | + public function merge_post_type_support($supports = array(), $is_hierarchical = false) { |
|
| 135 | + $supports = array_merge($this->post_type_support, $supports); |
|
| 136 | 136 | return $supports; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | * |
| 146 | 146 | * @return array Handles, merged with existing styles |
| 147 | 147 | */ |
| 148 | - public function merge_noconflict_styles( $handles ) { |
|
| 149 | - $handles = array_merge( $this->style_handles, $handles ); |
|
| 148 | + public function merge_noconflict_styles($handles) { |
|
| 149 | + $handles = array_merge($this->style_handles, $handles); |
|
| 150 | 150 | return $handles; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return array Handles, merged with existing scripts |
| 161 | 161 | */ |
| 162 | - public function merge_noconflict_scripts( $handles ) { |
|
| 163 | - $handles = array_merge( $this->script_handles, $handles ); |
|
| 162 | + public function merge_noconflict_scripts($handles) { |
|
| 163 | + $handles = array_merge($this->script_handles, $handles); |
|
| 164 | 164 | return $handles; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -174,8 +174,8 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return array Meta key array, merged with existing meta keys |
| 176 | 176 | */ |
| 177 | - public function merge_content_meta_keys( $meta_keys = array(), $post_id = 0 ) { |
|
| 178 | - return array_merge( $this->content_meta_keys, $meta_keys ); |
|
| 177 | + public function merge_content_meta_keys($meta_keys = array(), $post_id = 0) { |
|
| 178 | + return array_merge($this->content_meta_keys, $meta_keys); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | } |
| 182 | 182 | \ No newline at end of file |
@@ -51,6 +51,9 @@ |
||
| 51 | 51 | // hold widget View options |
| 52 | 52 | private $widget_options; |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $widget_id |
|
| 56 | + */ |
|
| 54 | 57 | function __construct( $widget_label , $widget_id , $defaults = array(), $settings = array() ) { |
| 55 | 58 | |
| 56 | 59 | |
@@ -116,12 +116,12 @@ |
||
| 116 | 116 | return $settings; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function get_widget_id() { |
|
| 123 | - return $this->widget_id; |
|
| 124 | - } |
|
| 119 | + /** |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function get_widget_id() { |
|
| 123 | + return $this->widget_id; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Get the widget settings |
@@ -51,37 +51,37 @@ discard block |
||
| 51 | 51 | // hold widget View options |
| 52 | 52 | private $widget_options; |
| 53 | 53 | |
| 54 | - function __construct( $widget_label , $widget_id , $defaults = array(), $settings = array() ) { |
|
| 54 | + function __construct($widget_label, $widget_id, $defaults = array(), $settings = array()) { |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The shortcode name is set to the lowercase name of the widget class, unless overridden by the class specifying a different value for $shortcode_name |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - $this->shortcode_name = !isset( $this->shortcode_name ) ? strtolower( get_class($this) ) : $this->shortcode_name; |
|
| 61 | + $this->shortcode_name = !isset($this->shortcode_name) ? strtolower(get_class($this)) : $this->shortcode_name; |
|
| 62 | 62 | |
| 63 | 63 | $this->widget_label = $widget_label; |
| 64 | 64 | $this->widget_id = $widget_id; |
| 65 | - $this->defaults = array_merge( array( 'header' => 0, 'footer' => 0 ), $defaults ); |
|
| 65 | + $this->defaults = array_merge(array('header' => 0, 'footer' => 0), $defaults); |
|
| 66 | 66 | |
| 67 | 67 | // Make sure every widget has a title, even if empty |
| 68 | 68 | $this->settings = $this->get_default_settings(); |
| 69 | - $this->settings = wp_parse_args( $settings, $this->settings ); |
|
| 69 | + $this->settings = wp_parse_args($settings, $this->settings); |
|
| 70 | 70 | |
| 71 | 71 | // register widgets to be listed in the View Configuration |
| 72 | - add_filter( 'gravityview_register_directory_widgets', array( $this, 'register_widget') ); |
|
| 72 | + add_filter('gravityview_register_directory_widgets', array($this, 'register_widget')); |
|
| 73 | 73 | |
| 74 | 74 | // widget options |
| 75 | - add_filter( 'gravityview_template_widget_options', array( $this, 'assign_widget_options' ), 10, 3 ); |
|
| 75 | + add_filter('gravityview_template_widget_options', array($this, 'assign_widget_options'), 10, 3); |
|
| 76 | 76 | |
| 77 | 77 | // frontend logic |
| 78 | - add_action( "gravityview_render_widget_{$widget_id}", array( $this, 'render_frontend' ), 10, 1 ); |
|
| 78 | + add_action("gravityview_render_widget_{$widget_id}", array($this, 'render_frontend'), 10, 1); |
|
| 79 | 79 | |
| 80 | 80 | // register shortcodes |
| 81 | - add_action( 'wp', array( $this, 'add_shortcode') ); |
|
| 81 | + add_action('wp', array($this, 'add_shortcode')); |
|
| 82 | 82 | |
| 83 | 83 | // Use shortcodes in text widgets. |
| 84 | - add_filter('widget_text', array( $this, 'maybe_do_shortcode' ) ); |
|
| 84 | + add_filter('widget_text', array($this, 'maybe_do_shortcode')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | * @param boolean $enable_custom_class False by default. Return true if you want to enable. |
| 100 | 100 | * @param GravityView_Widget $this Current instance of GravityView_Widget |
| 101 | 101 | */ |
| 102 | - $enable_custom_class = apply_filters('gravityview/widget/enable_custom_class', false, $this ); |
|
| 102 | + $enable_custom_class = apply_filters('gravityview/widget/enable_custom_class', false, $this); |
|
| 103 | 103 | |
| 104 | - if( $enable_custom_class ) { |
|
| 104 | + if ($enable_custom_class) { |
|
| 105 | 105 | |
| 106 | 106 | $settings['custom_class'] = array( |
| 107 | 107 | 'type' => 'text', |
| 108 | - 'label' => __( 'Custom CSS Class:', 'gravityview' ), |
|
| 109 | - 'desc' => __( 'This class will be added to the widget container', 'gravityview'), |
|
| 108 | + 'label' => __('Custom CSS Class:', 'gravityview'), |
|
| 109 | + 'desc' => __('This class will be added to the widget container', 'gravityview'), |
|
| 110 | 110 | 'value' => '', |
| 111 | 111 | 'merge_tags' => true, |
| 112 | 112 | ); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return array|null Settings array; NULL if not set |
| 129 | 129 | */ |
| 130 | 130 | public function get_settings() { |
| 131 | - return !empty( $this->settings ) ? $this->settings : NULL; |
|
| 131 | + return !empty($this->settings) ? $this->settings : NULL; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | * @param string $key Key for the setting |
| 137 | 137 | * @return mixed|null Value of the setting; NULL if not set |
| 138 | 138 | */ |
| 139 | - public function get_setting( $key ) { |
|
| 139 | + public function get_setting($key) { |
|
| 140 | 140 | $setting = NULL; |
| 141 | 141 | |
| 142 | - if( isset( $this->settings ) && is_array( $this->settings ) ) { |
|
| 143 | - $setting = isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : NULL; |
|
| 142 | + if (isset($this->settings) && is_array($this->settings)) { |
|
| 143 | + $setting = isset($this->settings[$key]) ? $this->settings[$key] : NULL; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | return $setting; |
@@ -152,20 +152,20 @@ discard block |
||
| 152 | 152 | * @param null|WP_Widget Empty if not called by WP_Widget, or a WP_Widget instance |
| 153 | 153 | * @return string Widget text |
| 154 | 154 | */ |
| 155 | - function maybe_do_shortcode( $text, $widget = NULL ) { |
|
| 155 | + function maybe_do_shortcode($text, $widget = NULL) { |
|
| 156 | 156 | |
| 157 | - if( !empty( $this->shortcode_name ) && has_shortcode( $text, $this->shortcode_name ) ) { |
|
| 158 | - return do_shortcode( $text ); |
|
| 157 | + if (!empty($this->shortcode_name) && has_shortcode($text, $this->shortcode_name)) { |
|
| 158 | + return do_shortcode($text); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | return $text; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - function render_shortcode( $atts, $content = '', $context = '' ) { |
|
| 164 | + function render_shortcode($atts, $content = '', $context = '') { |
|
| 165 | 165 | |
| 166 | 166 | ob_start(); |
| 167 | 167 | |
| 168 | - $this->render_frontend( $atts, $content, $context ); |
|
| 168 | + $this->render_frontend($atts, $content, $context); |
|
| 169 | 169 | |
| 170 | 170 | return ob_get_clean(); |
| 171 | 171 | } |
@@ -173,31 +173,31 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * Add $this->shortcode_name shortcode to output self::render_frontend() |
| 175 | 175 | */ |
| 176 | - function add_shortcode( $run_on_singular = true ) { |
|
| 176 | + function add_shortcode($run_on_singular = true) { |
|
| 177 | 177 | global $post; |
| 178 | 178 | |
| 179 | - if( GravityView_Plugin::is_admin() ) { return; } |
|
| 179 | + if (GravityView_Plugin::is_admin()) { return; } |
|
| 180 | 180 | |
| 181 | - if( empty( $this->shortcode_name ) ) { return; } |
|
| 181 | + if (empty($this->shortcode_name)) { return; } |
|
| 182 | 182 | |
| 183 | 183 | // If the widget shouldn't output on single entries, don't show it |
| 184 | - if( empty( $this->show_on_single ) && class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry() ) { |
|
| 185 | - do_action('gravityview_log_debug', sprintf( '%s[add_shortcode]: Skipping; set to not run on single entry.', get_class($this)) ); |
|
| 184 | + if (empty($this->show_on_single) && class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry()) { |
|
| 185 | + do_action('gravityview_log_debug', sprintf('%s[add_shortcode]: Skipping; set to not run on single entry.', get_class($this))); |
|
| 186 | 186 | |
| 187 | - add_shortcode( $this->shortcode_name, '__return_null' ); |
|
| 187 | + add_shortcode($this->shortcode_name, '__return_null'); |
|
| 188 | 188 | return; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | - if( !has_gravityview_shortcode( $post ) ) { |
|
| 192 | + if (!has_gravityview_shortcode($post)) { |
|
| 193 | 193 | |
| 194 | - do_action('gravityview_log_debug', sprintf( '%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class($this)) ); |
|
| 194 | + do_action('gravityview_log_debug', sprintf('%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class($this))); |
|
| 195 | 195 | |
| 196 | - add_shortcode( $this->shortcode_name, '__return_null' ); |
|
| 196 | + add_shortcode($this->shortcode_name, '__return_null'); |
|
| 197 | 197 | return; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - add_shortcode( $this->shortcode_name, array( $this, 'render_shortcode') ); |
|
| 200 | + add_shortcode($this->shortcode_name, array($this, 'render_shortcode')); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | * @param array $widgets |
| 206 | 206 | * @return array $widgets |
| 207 | 207 | */ |
| 208 | - function register_widget( $widgets ) { |
|
| 209 | - $widgets[ $this->widget_id ] = array( |
|
| 210 | - 'label' => $this->widget_label , |
|
| 208 | + function register_widget($widgets) { |
|
| 209 | + $widgets[$this->widget_id] = array( |
|
| 210 | + 'label' => $this->widget_label, |
|
| 211 | 211 | 'description' => $this->widget_description, |
| 212 | 212 | 'subtitle' => $this->widget_subtitle, |
| 213 | 213 | ); |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | * @param string $template (default: '') |
| 223 | 223 | * @return array |
| 224 | 224 | */ |
| 225 | - public function assign_widget_options( $options = array(), $template = '', $widget = '' ) { |
|
| 225 | + public function assign_widget_options($options = array(), $template = '', $widget = '') { |
|
| 226 | 226 | |
| 227 | - if( $this->widget_id === $widget ) { |
|
| 228 | - $options = array_merge( $options, $this->settings ); |
|
| 227 | + if ($this->widget_id === $widget) { |
|
| 228 | + $options = array_merge($options, $this->settings); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $options; |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return void |
| 239 | 239 | */ |
| 240 | - public function render_frontend( $widget_args, $content = '', $context = '') { |
|
| 240 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
| 241 | 241 | // to be defined by child class |
| 242 | - if( !$this->pre_render_frontend() ) { |
|
| 242 | + if (!$this->pre_render_frontend()) { |
|
| 243 | 243 | return; |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | public function pre_render_frontend() { |
| 252 | 252 | $gravityview_view = GravityView_View::getInstance(); |
| 253 | 253 | |
| 254 | - if( empty( $gravityview_view ) ) { |
|
| 255 | - do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class($this)) ); |
|
| 254 | + if (empty($gravityview_view)) { |
|
| 255 | + do_action('gravityview_log_debug', sprintf('%s[render_frontend]: $gravityview_view not instantiated yet.', get_class($this))); |
|
| 256 | 256 | return false; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -261,10 +261,10 @@ discard block |
||
| 261 | 261 | * @param boolean $hide_until_searched Hide until search? |
| 262 | 262 | * @param GravityView_Widget $this Widget instance |
| 263 | 263 | */ |
| 264 | - $hide_until_search = apply_filters( 'gravityview/widget/hide_until_searched', $gravityview_view->hide_until_searched, $this ); |
|
| 264 | + $hide_until_search = apply_filters('gravityview/widget/hide_until_searched', $gravityview_view->hide_until_searched, $this); |
|
| 265 | 265 | |
| 266 | - if( $hide_until_search ) { |
|
| 267 | - do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: Hide View data until search is performed', get_class($this)) ); |
|
| 266 | + if ($hide_until_search) { |
|
| 267 | + do_action('gravityview_log_debug', sprintf('%s[render_frontend]: Hide View data until search is performed', get_class($this))); |
|
| 268 | 268 | return false; |
| 269 | 269 | } |
| 270 | 270 | |
@@ -993,7 +993,7 @@ |
||
| 993 | 993 | /** |
| 994 | 994 | * Modify the array passed to wp_localize_script() |
| 995 | 995 | * |
| 996 | - * @param array $js_localization The data padded to the Javascript file |
|
| 996 | + * @param array $localizations The data padded to the Javascript file |
|
| 997 | 997 | * @param array $view_data View data array with View settings |
| 998 | 998 | * |
| 999 | 999 | * @return array |
@@ -384,16 +384,16 @@ |
||
| 384 | 384 | $curr_start = esc_attr( rgget( 'gv_start' ) ); |
| 385 | 385 | $curr_end = esc_attr( rgget( 'gv_end' ) ); |
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n |
|
| 389 | - * date_created is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php) |
|
| 390 | - * @since 1.12 |
|
| 391 | - * @param[out,in] boolean $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true |
|
| 392 | - * @param[in] string $context Where the filter is being called from. `search` in this case. |
|
| 393 | - */ |
|
| 394 | - $adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', true, 'search' ); |
|
| 395 | - $search_criteria['start_date'] = ( $adjust_tz && !empty( $curr_start ) ) ? get_gmt_from_date( $curr_start ) : $curr_start; |
|
| 396 | - $search_criteria['end_date'] = ( $adjust_tz && !empty( $curr_end ) ) ? get_gmt_from_date( $curr_end ) : $curr_end; |
|
| 387 | + /** |
|
| 388 | + * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n |
|
| 389 | + * date_created is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php) |
|
| 390 | + * @since 1.12 |
|
| 391 | + * @param[out,in] boolean $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true |
|
| 392 | + * @param[in] string $context Where the filter is being called from. `search` in this case. |
|
| 393 | + */ |
|
| 394 | + $adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', true, 'search' ); |
|
| 395 | + $search_criteria['start_date'] = ( $adjust_tz && !empty( $curr_start ) ) ? get_gmt_from_date( $curr_start ) : $curr_start; |
|
| 396 | + $search_criteria['end_date'] = ( $adjust_tz && !empty( $curr_end ) ) ? get_gmt_from_date( $curr_end ) : $curr_end; |
|
| 397 | 397 | |
| 398 | 398 | |
| 399 | 399 | // search for a specific entry ID |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @copyright Copyright 2014, Katz Web Services, Inc. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( ! defined( 'WPINC' ) ) { |
|
| 12 | +if (!defined('WPINC')) { |
|
| 13 | 13 | die; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -22,28 +22,28 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function __construct() { |
| 24 | 24 | |
| 25 | - $this->widget_description = esc_html__( 'Search form for searching entries.', 'gravityview' ); |
|
| 25 | + $this->widget_description = esc_html__('Search form for searching entries.', 'gravityview'); |
|
| 26 | 26 | |
| 27 | 27 | self::$instance = &$this; |
| 28 | 28 | |
| 29 | - self::$file = plugin_dir_path( __FILE__ ); |
|
| 29 | + self::$file = plugin_dir_path(__FILE__); |
|
| 30 | 30 | |
| 31 | - $default_values = array( 'header' => 0, 'footer' => 0 ); |
|
| 31 | + $default_values = array('header' => 0, 'footer' => 0); |
|
| 32 | 32 | |
| 33 | 33 | $settings = array( |
| 34 | 34 | 'search_layout' => array( |
| 35 | 35 | 'type' => 'radio', |
| 36 | 36 | 'full_width' => true, |
| 37 | - 'label' => esc_html__( 'Search Layout', 'gravityview' ), |
|
| 37 | + 'label' => esc_html__('Search Layout', 'gravityview'), |
|
| 38 | 38 | 'value' => 'horizontal', |
| 39 | 39 | 'options' => array( |
| 40 | - 'horizontal' => esc_html__( 'Horizontal', 'gravityview' ), |
|
| 41 | - 'vertical' => esc_html__( 'Vertical', 'gravityview' ), |
|
| 40 | + 'horizontal' => esc_html__('Horizontal', 'gravityview'), |
|
| 41 | + 'vertical' => esc_html__('Vertical', 'gravityview'), |
|
| 42 | 42 | ), |
| 43 | 43 | ), |
| 44 | 44 | 'search_clear' => array( |
| 45 | 45 | 'type' => 'checkbox', |
| 46 | - 'label' => __( 'Show Clear button', 'gravityview' ), |
|
| 46 | + 'label' => __('Show Clear button', 'gravityview'), |
|
| 47 | 47 | 'value' => false, |
| 48 | 48 | ), |
| 49 | 49 | 'search_fields' => array( |
@@ -55,33 +55,33 @@ discard block |
||
| 55 | 55 | 'search_mode' => array( |
| 56 | 56 | 'type' => 'radio', |
| 57 | 57 | 'full_width' => true, |
| 58 | - 'label' => esc_html__( 'Search Mode', 'gravityview' ), |
|
| 58 | + 'label' => esc_html__('Search Mode', 'gravityview'), |
|
| 59 | 59 | 'desc' => __('Should search results match all search fields, or any?', 'gravityview'), |
| 60 | 60 | 'value' => 'any', |
| 61 | 61 | 'class' => 'hide-if-js', |
| 62 | 62 | 'options' => array( |
| 63 | - 'any' => esc_html__( 'Match Any Fields', 'gravityview' ), |
|
| 64 | - 'all' => esc_html__( 'Match All Fields', 'gravityview' ), |
|
| 63 | + 'any' => esc_html__('Match Any Fields', 'gravityview'), |
|
| 64 | + 'all' => esc_html__('Match All Fields', 'gravityview'), |
|
| 65 | 65 | ), |
| 66 | 66 | ), |
| 67 | 67 | ); |
| 68 | - parent::__construct( esc_html__( 'Search Bar', 'gravityview' ), 'search_bar', $default_values, $settings ); |
|
| 68 | + parent::__construct(esc_html__('Search Bar', 'gravityview'), 'search_bar', $default_values, $settings); |
|
| 69 | 69 | |
| 70 | 70 | // frontend - filter entries |
| 71 | - add_filter( 'gravityview_fe_search_criteria', array( $this, 'filter_entries' ), 10, 1 ); |
|
| 71 | + add_filter('gravityview_fe_search_criteria', array($this, 'filter_entries'), 10, 1); |
|
| 72 | 72 | |
| 73 | 73 | // frontend - add template path |
| 74 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 74 | + add_filter('gravityview_template_paths', array($this, 'add_template_path')); |
|
| 75 | 75 | |
| 76 | 76 | // Add hidden fields for "Default" permalink structure |
| 77 | - add_filter( 'gravityview_widget_search_filters', array( $this, 'add_no_permalink_fields' ), 10, 3 ); |
|
| 77 | + add_filter('gravityview_widget_search_filters', array($this, 'add_no_permalink_fields'), 10, 3); |
|
| 78 | 78 | |
| 79 | 79 | // admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999 |
| 80 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles' ), 1100 ); |
|
| 81 | - add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict' ) ); |
|
| 80 | + add_action('admin_enqueue_scripts', array($this, 'add_scripts_and_styles'), 1100); |
|
| 81 | + add_filter('gravityview_noconflict_scripts', array($this, 'register_no_conflict')); |
|
| 82 | 82 | |
| 83 | 83 | // ajax - get the searchable fields |
| 84 | - add_action( 'wp_ajax_gv_searchable_fields', array( 'GravityView_Widget_Search', 'get_searchable_fields' ) ); |
|
| 84 | + add_action('wp_ajax_gv_searchable_fields', array('GravityView_Widget_Search', 'get_searchable_fields')); |
|
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return GravityView_Widget_Search |
| 90 | 90 | */ |
| 91 | 91 | public static function getInstance() { |
| 92 | - if ( empty( self::$instance ) ) { |
|
| 92 | + if (empty(self::$instance)) { |
|
| 93 | 93 | self::$instance = new GravityView_Widget_Search; |
| 94 | 94 | } |
| 95 | 95 | return self::$instance; |
@@ -100,18 +100,18 @@ discard block |
||
| 100 | 100 | * Add script to Views edit screen (admin) |
| 101 | 101 | * @param mixed $hook |
| 102 | 102 | */ |
| 103 | - public function add_scripts_and_styles( $hook ) { |
|
| 103 | + public function add_scripts_and_styles($hook) { |
|
| 104 | 104 | global $pagenow; |
| 105 | 105 | |
| 106 | 106 | // Don't process any scripts below here if it's not a GravityView page or the widgets screen |
| 107 | - if ( ! gravityview_is_admin_page( $hook ) && ( 'widgets.php' !== $pagenow ) ) { |
|
| 107 | + if (!gravityview_is_admin_page($hook) && ('widgets.php' !== $pagenow)) { |
|
| 108 | 108 | return; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $script_min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
| 112 | - $script_source = empty( $script_min ) ? '/source' : ''; |
|
| 111 | + $script_min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
| 112 | + $script_source = empty($script_min) ? '/source' : ''; |
|
| 113 | 113 | |
| 114 | - wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__ ), array( 'jquery', 'gravityview_views_scripts' ), GravityView_Plugin::version ); |
|
| 114 | + wp_enqueue_script('gravityview_searchwidget_admin', plugins_url('assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__), array('jquery', 'gravityview_views_scripts'), GravityView_Plugin::version); |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -120,15 +120,15 @@ discard block |
||
| 120 | 120 | * @var array |
| 121 | 121 | */ |
| 122 | 122 | $input_labels = array( |
| 123 | - 'input_text' => esc_html__( 'Text', 'gravityview' ), |
|
| 124 | - 'date' => esc_html__( 'Date', 'gravityview' ), |
|
| 125 | - 'select' => esc_html__( 'Select', 'gravityview' ), |
|
| 126 | - 'multiselect' => esc_html__( 'Select (multiple values)', 'gravityview' ), |
|
| 127 | - 'radio' => esc_html__( 'Radio', 'gravityview' ), |
|
| 128 | - 'checkbox' => esc_html__( 'Checkbox', 'gravityview' ), |
|
| 129 | - 'single_checkbox' => esc_html__( 'Checkbox', 'gravityview' ), |
|
| 130 | - 'link' => esc_html__( 'Links', 'gravityview' ), |
|
| 131 | - 'date_range' => esc_html__( 'Date range', 'gravityview' ), |
|
| 123 | + 'input_text' => esc_html__('Text', 'gravityview'), |
|
| 124 | + 'date' => esc_html__('Date', 'gravityview'), |
|
| 125 | + 'select' => esc_html__('Select', 'gravityview'), |
|
| 126 | + 'multiselect' => esc_html__('Select (multiple values)', 'gravityview'), |
|
| 127 | + 'radio' => esc_html__('Radio', 'gravityview'), |
|
| 128 | + 'checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
| 129 | + 'single_checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
| 130 | + 'link' => esc_html__('Links', 'gravityview'), |
|
| 131 | + 'date_range' => esc_html__('Date range', 'gravityview'), |
|
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -137,31 +137,31 @@ discard block |
||
| 137 | 137 | * @var array |
| 138 | 138 | */ |
| 139 | 139 | $input_types = array( |
| 140 | - 'text' => array( 'input_text' ), |
|
| 141 | - 'address' => array( 'input_text' ), |
|
| 142 | - 'date' => array( 'date', 'date_range' ), |
|
| 143 | - 'boolean' => array( 'single_checkbox' ), |
|
| 144 | - 'select' => array( 'select', 'radio', 'link' ), |
|
| 145 | - 'multi' => array( 'select', 'multiselect', 'radio', 'checkbox', 'link' ), |
|
| 140 | + 'text' => array('input_text'), |
|
| 141 | + 'address' => array('input_text'), |
|
| 142 | + 'date' => array('date', 'date_range'), |
|
| 143 | + 'boolean' => array('single_checkbox'), |
|
| 144 | + 'select' => array('select', 'radio', 'link'), |
|
| 145 | + 'multi' => array('select', 'multiselect', 'radio', 'checkbox', 'link'), |
|
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | - wp_localize_script( 'gravityview_searchwidget_admin', 'gvSearchVar', array( |
|
| 149 | - 'nonce' => wp_create_nonce( 'gravityview_ajaxsearchwidget' ), |
|
| 150 | - 'label_nofields' => esc_html__( 'No search fields configured yet.', 'gravityview' ), |
|
| 151 | - 'label_addfield' => esc_html__( 'Add Search Field', 'gravityview' ), |
|
| 152 | - 'label_label' => esc_html__( 'Label', 'gravityview' ), |
|
| 153 | - 'label_searchfield' => esc_html__( 'Search Field', 'gravityview' ), |
|
| 154 | - 'label_inputtype' => esc_html__( 'Input Type', 'gravityview' ), |
|
| 155 | - 'input_labels' => json_encode( $input_labels ), |
|
| 156 | - 'input_types' => json_encode( $input_types ), |
|
| 157 | - ) ); |
|
| 148 | + wp_localize_script('gravityview_searchwidget_admin', 'gvSearchVar', array( |
|
| 149 | + 'nonce' => wp_create_nonce('gravityview_ajaxsearchwidget'), |
|
| 150 | + 'label_nofields' => esc_html__('No search fields configured yet.', 'gravityview'), |
|
| 151 | + 'label_addfield' => esc_html__('Add Search Field', 'gravityview'), |
|
| 152 | + 'label_label' => esc_html__('Label', 'gravityview'), |
|
| 153 | + 'label_searchfield' => esc_html__('Search Field', 'gravityview'), |
|
| 154 | + 'label_inputtype' => esc_html__('Input Type', 'gravityview'), |
|
| 155 | + 'input_labels' => json_encode($input_labels), |
|
| 156 | + 'input_types' => json_encode($input_types), |
|
| 157 | + )); |
|
| 158 | 158 | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Add admin script to the whitelist |
| 163 | 163 | */ |
| 164 | - public function register_no_conflict( $required ) { |
|
| 164 | + public function register_no_conflict($required) { |
|
| 165 | 165 | $required[] = 'gravityview_searchwidget_admin'; |
| 166 | 166 | return $required; |
| 167 | 167 | } |
@@ -175,30 +175,30 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public static function get_searchable_fields() { |
| 177 | 177 | |
| 178 | - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gravityview_ajaxsearchwidget' ) ) { |
|
| 179 | - exit( 0 ); |
|
| 178 | + if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxsearchwidget')) { |
|
| 179 | + exit(0); |
|
| 180 | 180 | } |
| 181 | 181 | $form = ''; |
| 182 | 182 | |
| 183 | 183 | // Fetch the form for the current View |
| 184 | - if ( ! empty( $_POST['view_id'] ) ) { |
|
| 184 | + if (!empty($_POST['view_id'])) { |
|
| 185 | 185 | |
| 186 | - $form = gravityview_get_form_id( $_POST['view_id'] ); |
|
| 186 | + $form = gravityview_get_form_id($_POST['view_id']); |
|
| 187 | 187 | |
| 188 | - } elseif ( ! empty( $_POST['formid'] ) ) { |
|
| 188 | + } elseif (!empty($_POST['formid'])) { |
|
| 189 | 189 | |
| 190 | - $form = (int) $_POST['formid']; |
|
| 190 | + $form = (int)$_POST['formid']; |
|
| 191 | 191 | |
| 192 | - } elseif ( ! empty( $_POST['template_id'] ) && class_exists( 'GravityView_Ajax' ) ) { |
|
| 192 | + } elseif (!empty($_POST['template_id']) && class_exists('GravityView_Ajax')) { |
|
| 193 | 193 | |
| 194 | - $form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] ); |
|
| 194 | + $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); |
|
| 195 | 195 | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // fetch form id assigned to the view |
| 199 | - $response = self::render_searchable_fields( $form ); |
|
| 199 | + $response = self::render_searchable_fields($form); |
|
| 200 | 200 | |
| 201 | - exit( $response ); |
|
| 201 | + exit($response); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -207,14 +207,14 @@ discard block |
||
| 207 | 207 | * @param string $current (for future use) |
| 208 | 208 | * @return string |
| 209 | 209 | */ |
| 210 | - public static function render_searchable_fields( $form_id = null, $current = '' ) { |
|
| 210 | + public static function render_searchable_fields($form_id = null, $current = '') { |
|
| 211 | 211 | |
| 212 | - if ( is_null( $form_id ) ) { |
|
| 212 | + if (is_null($form_id)) { |
|
| 213 | 213 | return ''; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Get fields with sub-inputs and no parent |
| 217 | - $fields = gravityview_get_form_fields( $form_id, true, true ); |
|
| 217 | + $fields = gravityview_get_form_fields($form_id, true, true); |
|
| 218 | 218 | |
| 219 | 219 | // start building output |
| 220 | 220 | |
@@ -222,40 +222,40 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | $custom_fields = array( |
| 224 | 224 | 'search_all' => array( |
| 225 | - 'text' => esc_html__( 'Search Everything', 'gravityview' ), |
|
| 225 | + 'text' => esc_html__('Search Everything', 'gravityview'), |
|
| 226 | 226 | 'type' => 'text', |
| 227 | 227 | ), |
| 228 | 228 | 'entry_date' => array( |
| 229 | - 'text' => esc_html__( 'Entry Date', 'gravityview' ), |
|
| 229 | + 'text' => esc_html__('Entry Date', 'gravityview'), |
|
| 230 | 230 | 'type' => 'date', |
| 231 | 231 | ), |
| 232 | 232 | 'entry_id' => array( |
| 233 | - 'text' => esc_html__( 'Entry ID', 'gravityview' ), |
|
| 233 | + 'text' => esc_html__('Entry ID', 'gravityview'), |
|
| 234 | 234 | 'type' => 'text', |
| 235 | 235 | ), |
| 236 | 236 | 'created_by' => array( |
| 237 | - 'text' => esc_html__( 'Entry Creator', 'gravityview' ), |
|
| 237 | + 'text' => esc_html__('Entry Creator', 'gravityview'), |
|
| 238 | 238 | 'type' => 'select', |
| 239 | 239 | ) |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | - foreach( $custom_fields as $custom_field_key => $custom_field ) { |
|
| 243 | - $output .= sprintf( '<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected( $custom_field_key, $current, false ), $custom_field['type'], self::get_field_label( array('field' => $custom_field_key ) ), $custom_field['text'] ); |
|
| 242 | + foreach ($custom_fields as $custom_field_key => $custom_field) { |
|
| 243 | + $output .= sprintf('<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected($custom_field_key, $current, false), $custom_field['type'], self::get_field_label(array('field' => $custom_field_key)), $custom_field['text']); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if ( ! empty( $fields ) ) { |
|
| 246 | + if (!empty($fields)) { |
|
| 247 | 247 | |
| 248 | - $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array( 'fileupload', 'post_image', 'post_id' ), null ); |
|
| 248 | + $blacklist_field_types = apply_filters('gravityview_blacklist_field_types', array('fileupload', 'post_image', 'post_id'), null); |
|
| 249 | 249 | |
| 250 | - foreach ( $fields as $id => $field ) { |
|
| 250 | + foreach ($fields as $id => $field) { |
|
| 251 | 251 | |
| 252 | - if ( in_array( $field['type'], $blacklist_field_types ) ) { |
|
| 252 | + if (in_array($field['type'], $blacklist_field_types)) { |
|
| 253 | 253 | continue; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $types = self::get_search_input_types( $id, $field['type'] ); |
|
| 256 | + $types = self::get_search_input_types($id, $field['type']); |
|
| 257 | 257 | |
| 258 | - $output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'data-inputtypes="'. esc_attr( $types ) .'">'. esc_html( $field['label'] ) .'</option>'; |
|
| 258 | + $output .= '<option value="'.$id.'" '.selected($id, $current, false).'data-inputtypes="'.esc_attr($types).'">'.esc_html($field['label']).'</option>'; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
@@ -274,21 +274,21 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
| 276 | 276 | */ |
| 277 | - public static function get_search_input_types( $id = '', $field_type = null ) { |
|
| 277 | + public static function get_search_input_types($id = '', $field_type = null) { |
|
| 278 | 278 | |
| 279 | 279 | // @todo - This needs to be improved - many fields have . including products and addresses |
| 280 | - if ( false !== strpos( (string) $id, '.' ) && in_array( $field_type, array( 'checkbox' ) ) || in_array( $id, array( 'is_fulfilled' ) ) ) { |
|
| 280 | + if (false !== strpos((string)$id, '.') && in_array($field_type, array('checkbox')) || in_array($id, array('is_fulfilled'))) { |
|
| 281 | 281 | // on/off checkbox |
| 282 | 282 | $input_type = 'boolean'; |
| 283 | - } elseif ( in_array( $field_type, array( 'checkbox', 'post_category', 'multiselect' ) ) ) { |
|
| 283 | + } elseif (in_array($field_type, array('checkbox', 'post_category', 'multiselect'))) { |
|
| 284 | 284 | //multiselect |
| 285 | 285 | $input_type = 'multi'; |
| 286 | 286 | |
| 287 | - } elseif ( in_array( $field_type, array( 'select', 'radio' ) ) ) { |
|
| 287 | + } elseif (in_array($field_type, array('select', 'radio'))) { |
|
| 288 | 288 | //single select |
| 289 | 289 | $input_type = 'select'; |
| 290 | 290 | |
| 291 | - } elseif ( in_array( $field_type, array( 'date' ) ) || in_array( $id, array( 'payment_date' ) ) ) { |
|
| 291 | + } elseif (in_array($field_type, array('date')) || in_array($id, array('payment_date'))) { |
|
| 292 | 292 | // date |
| 293 | 293 | $input_type = 'date'; |
| 294 | 294 | } else { |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param string $field_type Gravity Forms field type |
| 303 | 303 | * @since 1.2 |
| 304 | 304 | */ |
| 305 | - $input_type = apply_filters( 'gravityview/extension/search/input_type', $input_type, $field_type ); |
|
| 305 | + $input_type = apply_filters('gravityview/extension/search/input_type', $input_type, $field_type); |
|
| 306 | 306 | |
| 307 | 307 | return $input_type; |
| 308 | 308 | } |
@@ -313,29 +313,29 @@ discard block |
||
| 313 | 313 | * @since 1.8 |
| 314 | 314 | * @return array Search fields, modified if not using permalinks |
| 315 | 315 | */ |
| 316 | - public function add_no_permalink_fields( $search_fields, $object, $widget_args = array() ) { |
|
| 316 | + public function add_no_permalink_fields($search_fields, $object, $widget_args = array()) { |
|
| 317 | 317 | /** @global WP_Rewrite $wp_rewrite */ |
| 318 | 318 | global $wp_rewrite; |
| 319 | 319 | |
| 320 | 320 | // Support default permalink structure |
| 321 | - if ( false === $wp_rewrite->using_permalinks() ) { |
|
| 321 | + if (false === $wp_rewrite->using_permalinks()) { |
|
| 322 | 322 | |
| 323 | 323 | // By default, use current post. |
| 324 | 324 | $post_id = 0; |
| 325 | 325 | |
| 326 | 326 | // We're in the WordPress Widget context, and an overriding post ID has been set. |
| 327 | - if ( ! empty( $widget_args['post_id'] ) ) { |
|
| 328 | - $post_id = absint( $widget_args['post_id'] ); |
|
| 327 | + if (!empty($widget_args['post_id'])) { |
|
| 328 | + $post_id = absint($widget_args['post_id']); |
|
| 329 | 329 | } |
| 330 | 330 | // We're in the WordPress Widget context, and the base View ID should be used |
| 331 | - else if ( ! empty( $widget_args['view_id'] ) ) { |
|
| 332 | - $post_id = absint( $widget_args['view_id'] ); |
|
| 331 | + else if (!empty($widget_args['view_id'])) { |
|
| 332 | + $post_id = absint($widget_args['view_id']); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - $args = gravityview_get_permalink_query_args( $post_id ); |
|
| 335 | + $args = gravityview_get_permalink_query_args($post_id); |
|
| 336 | 336 | |
| 337 | 337 | // Add hidden fields to the search form |
| 338 | - foreach ( $args as $key => $value ) { |
|
| 338 | + foreach ($args as $key => $value) { |
|
| 339 | 339 | $search_fields[] = array( |
| 340 | 340 | 'name' => $key, |
| 341 | 341 | 'input' => 'hidden', |
@@ -355,23 +355,23 @@ discard block |
||
| 355 | 355 | * @param array $search_criteria |
| 356 | 356 | * @return array |
| 357 | 357 | */ |
| 358 | - public function filter_entries( $search_criteria ) { |
|
| 358 | + public function filter_entries($search_criteria) { |
|
| 359 | 359 | |
| 360 | - do_action( 'gravityview_log_debug', sprintf( '%s[filter_entries] Requested $_GET: ', get_class( $this ) ), $_GET ); |
|
| 360 | + do_action('gravityview_log_debug', sprintf('%s[filter_entries] Requested $_GET: ', get_class($this)), $_GET); |
|
| 361 | 361 | |
| 362 | - if ( empty( $_GET ) || ! is_array( $_GET ) ) { |
|
| 362 | + if (empty($_GET) || !is_array($_GET)) { |
|
| 363 | 363 | return $search_criteria; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // add free search |
| 367 | - if ( ! empty( $_GET['gv_search'] ) ) { |
|
| 367 | + if (!empty($_GET['gv_search'])) { |
|
| 368 | 368 | |
| 369 | 369 | // Search for a piece |
| 370 | - $words = explode( ' ', stripslashes_deep( urldecode( $_GET['gv_search'] ) ) ); |
|
| 370 | + $words = explode(' ', stripslashes_deep(urldecode($_GET['gv_search']))); |
|
| 371 | 371 | |
| 372 | - $words = array_filter( $words ); |
|
| 372 | + $words = array_filter($words); |
|
| 373 | 373 | |
| 374 | - foreach ( $words as $word ) { |
|
| 374 | + foreach ($words as $word) { |
|
| 375 | 375 | $search_criteria['field_filters'][] = array( |
| 376 | 376 | 'key' => null, // The field ID to search |
| 377 | 377 | 'value' => $word, // The value to search |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | //start date & end date |
| 384 | - $curr_start = esc_attr( rgget( 'gv_start' ) ); |
|
| 385 | - $curr_end = esc_attr( rgget( 'gv_end' ) ); |
|
| 384 | + $curr_start = esc_attr(rgget('gv_start')); |
|
| 385 | + $curr_end = esc_attr(rgget('gv_end')); |
|
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n |
@@ -391,51 +391,51 @@ discard block |
||
| 391 | 391 | * @param[out,in] boolean $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true |
| 392 | 392 | * @param[in] string $context Where the filter is being called from. `search` in this case. |
| 393 | 393 | */ |
| 394 | - $adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', true, 'search' ); |
|
| 395 | - $search_criteria['start_date'] = ( $adjust_tz && !empty( $curr_start ) ) ? get_gmt_from_date( $curr_start ) : $curr_start; |
|
| 396 | - $search_criteria['end_date'] = ( $adjust_tz && !empty( $curr_end ) ) ? get_gmt_from_date( $curr_end ) : $curr_end; |
|
| 394 | + $adjust_tz = apply_filters('gravityview_date_created_adjust_timezone', true, 'search'); |
|
| 395 | + $search_criteria['start_date'] = ($adjust_tz && !empty($curr_start)) ? get_gmt_from_date($curr_start) : $curr_start; |
|
| 396 | + $search_criteria['end_date'] = ($adjust_tz && !empty($curr_end)) ? get_gmt_from_date($curr_end) : $curr_end; |
|
| 397 | 397 | |
| 398 | 398 | |
| 399 | 399 | // search for a specific entry ID |
| 400 | - if ( ! empty( $_GET[ 'gv_id' ] ) ) { |
|
| 400 | + if (!empty($_GET['gv_id'])) { |
|
| 401 | 401 | $search_criteria['field_filters'][] = array( |
| 402 | 402 | 'key' => 'id', |
| 403 | - 'value' => absint( $_GET[ 'gv_id' ] ), |
|
| 403 | + 'value' => absint($_GET['gv_id']), |
|
| 404 | 404 | 'operator' => '=', |
| 405 | 405 | ); |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // search for a specific Created_by ID |
| 409 | - if ( ! empty( $_GET[ 'gv_by' ] ) ) { |
|
| 409 | + if (!empty($_GET['gv_by'])) { |
|
| 410 | 410 | $search_criteria['field_filters'][] = array( |
| 411 | 411 | 'key' => 'created_by', |
| 412 | - 'value' => absint( $_GET['gv_by'] ), |
|
| 412 | + 'value' => absint($_GET['gv_by']), |
|
| 413 | 413 | 'operator' => '=', |
| 414 | 414 | ); |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
| 418 | 418 | // Get search mode passed in URL |
| 419 | - $mode = in_array( rgget( 'mode' ), array( 'any', 'all' ) ) ? esc_attr( rgget( 'mode' ) ) : 'any'; |
|
| 419 | + $mode = in_array(rgget('mode'), array('any', 'all')) ? esc_attr(rgget('mode')) : 'any'; |
|
| 420 | 420 | |
| 421 | 421 | // get the other search filters |
| 422 | - foreach ( $_GET as $key => $value ) { |
|
| 422 | + foreach ($_GET as $key => $value) { |
|
| 423 | 423 | |
| 424 | - if ( 0 !== strpos( $key, 'filter_' ) || empty( $value ) || ( is_array( $value ) && count( $value ) === 1 && empty( $value[0] ) ) ) { |
|
| 424 | + if (0 !== strpos($key, 'filter_') || empty($value) || (is_array($value) && count($value) === 1 && empty($value[0]))) { |
|
| 425 | 425 | continue; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | // could return simple filter or multiple filters |
| 429 | - $filter = $this->prepare_field_filter( $key, $value ); |
|
| 429 | + $filter = $this->prepare_field_filter($key, $value); |
|
| 430 | 430 | |
| 431 | - if ( isset( $filter[0]['value'] ) ) { |
|
| 432 | - $search_criteria['field_filters'] = array_merge( $search_criteria['field_filters'], $filter ); |
|
| 431 | + if (isset($filter[0]['value'])) { |
|
| 432 | + $search_criteria['field_filters'] = array_merge($search_criteria['field_filters'], $filter); |
|
| 433 | 433 | |
| 434 | 434 | // if date range type, set search mode to ALL |
| 435 | - if ( ! empty( $filter[0]['operator'] ) && in_array( $filter[0]['operator'], array( '>', '<' ) ) ) { |
|
| 435 | + if (!empty($filter[0]['operator']) && in_array($filter[0]['operator'], array('>', '<'))) { |
|
| 436 | 436 | $mode = 'all'; |
| 437 | 437 | } |
| 438 | - } elseif( !empty( $filter ) ) { |
|
| 438 | + } elseif (!empty($filter)) { |
|
| 439 | 439 | $search_criteria['field_filters'][] = $filter; |
| 440 | 440 | } |
| 441 | 441 | } |
@@ -445,9 +445,9 @@ discard block |
||
| 445 | 445 | * @since 1.5.1 |
| 446 | 446 | * @param[out,in] string $mode Search mode (`any` vs `all`) |
| 447 | 447 | */ |
| 448 | - $search_criteria['field_filters']['mode'] = apply_filters( 'gravityview/search/mode', $mode ); |
|
| 448 | + $search_criteria['field_filters']['mode'] = apply_filters('gravityview/search/mode', $mode); |
|
| 449 | 449 | |
| 450 | - do_action( 'gravityview_log_debug', sprintf( '%s[filter_entries] Returned Search Criteria: ', get_class( $this ) ), $search_criteria ); |
|
| 450 | + do_action('gravityview_log_debug', sprintf('%s[filter_entries] Returned Search Criteria: ', get_class($this)), $search_criteria); |
|
| 451 | 451 | |
| 452 | 452 | return $search_criteria; |
| 453 | 453 | } |
@@ -462,16 +462,16 @@ discard block |
||
| 462 | 462 | * @param string $value $_GET search value |
| 463 | 463 | * @return array 1 or 2 deph levels |
| 464 | 464 | */ |
| 465 | - public function prepare_field_filter( $key, $value ) { |
|
| 465 | + public function prepare_field_filter($key, $value) { |
|
| 466 | 466 | |
| 467 | 467 | $gravityview_view = GravityView_View::getInstance(); |
| 468 | 468 | |
| 469 | 469 | // calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox ) |
| 470 | - $field_id = str_replace( '_', '.', str_replace( 'filter_', '', $key ) ); |
|
| 470 | + $field_id = str_replace('_', '.', str_replace('filter_', '', $key)); |
|
| 471 | 471 | |
| 472 | 472 | // get form field array |
| 473 | 473 | $form = $gravityview_view->getForm(); |
| 474 | - $form_field = gravityview_get_field( $form, $field_id ); |
|
| 474 | + $form_field = gravityview_get_field($form, $field_id); |
|
| 475 | 475 | |
| 476 | 476 | // default filter array |
| 477 | 477 | $filter = array( |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | 'value' => $value, |
| 480 | 480 | ); |
| 481 | 481 | |
| 482 | - switch ( $form_field['type'] ) { |
|
| 482 | + switch ($form_field['type']) { |
|
| 483 | 483 | |
| 484 | 484 | case 'select': |
| 485 | 485 | case 'radio': |
@@ -488,18 +488,18 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | case 'post_category': |
| 490 | 490 | |
| 491 | - if ( ! is_array( $value ) ) { |
|
| 492 | - $value = array( $value ); |
|
| 491 | + if (!is_array($value)) { |
|
| 492 | + $value = array($value); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Reset filter variable |
| 496 | 496 | $filter = array(); |
| 497 | 497 | |
| 498 | - foreach ( $value as $val ) { |
|
| 499 | - $cat = get_term( $val, 'category' ); |
|
| 498 | + foreach ($value as $val) { |
|
| 499 | + $cat = get_term($val, 'category'); |
|
| 500 | 500 | $filter[] = array( |
| 501 | 501 | 'key' => $field_id, |
| 502 | - 'value' => esc_attr( $cat->name ) . ':' . $val, |
|
| 502 | + 'value' => esc_attr($cat->name).':'.$val, |
|
| 503 | 503 | 'operator' => 'is', |
| 504 | 504 | ); |
| 505 | 505 | } |
@@ -508,35 +508,35 @@ discard block |
||
| 508 | 508 | |
| 509 | 509 | case 'multiselect': |
| 510 | 510 | |
| 511 | - if ( ! is_array( $value ) ) { |
|
| 511 | + if (!is_array($value)) { |
|
| 512 | 512 | break; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // Reset filter variable |
| 516 | 516 | $filter = array(); |
| 517 | 517 | |
| 518 | - foreach ( $value as $val ) { |
|
| 519 | - $filter[] = array( 'key' => $field_id, 'value' => $val ); |
|
| 518 | + foreach ($value as $val) { |
|
| 519 | + $filter[] = array('key' => $field_id, 'value' => $val); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | break; |
| 523 | 523 | |
| 524 | 524 | case 'checkbox': |
| 525 | 525 | // convert checkbox on/off into the correct search filter |
| 526 | - if ( false !== strpos( $field_id, '.' ) && ! empty( $form_field['inputs'] ) && ! empty( $form_field['choices'] ) ) { |
|
| 527 | - foreach ( $form_field['inputs'] as $k => $input ) { |
|
| 528 | - if ( $input['id'] == $field_id ) { |
|
| 529 | - $filter['value'] = $form_field['choices'][ $k ]['value']; |
|
| 526 | + if (false !== strpos($field_id, '.') && !empty($form_field['inputs']) && !empty($form_field['choices'])) { |
|
| 527 | + foreach ($form_field['inputs'] as $k => $input) { |
|
| 528 | + if ($input['id'] == $field_id) { |
|
| 529 | + $filter['value'] = $form_field['choices'][$k]['value']; |
|
| 530 | 530 | $filter['operator'] = 'is'; |
| 531 | 531 | break; |
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | - } elseif ( is_array( $value ) ) { |
|
| 534 | + } elseif (is_array($value)) { |
|
| 535 | 535 | |
| 536 | 536 | // Reset filter variable |
| 537 | 537 | $filter = array(); |
| 538 | 538 | |
| 539 | - foreach ( $value as $val ) { |
|
| 539 | + foreach ($value as $val) { |
|
| 540 | 540 | $filter[] = array( |
| 541 | 541 | 'key' => $field_id, |
| 542 | 542 | 'value' => $val, |
@@ -550,13 +550,13 @@ discard block |
||
| 550 | 550 | case 'name': |
| 551 | 551 | case 'address': |
| 552 | 552 | |
| 553 | - if ( false === strpos( $field_id, '.' ) ) { |
|
| 553 | + if (false === strpos($field_id, '.')) { |
|
| 554 | 554 | |
| 555 | - $words = explode( ' ', $value ); |
|
| 555 | + $words = explode(' ', $value); |
|
| 556 | 556 | |
| 557 | 557 | $filters = array(); |
| 558 | - foreach ( $words as $word ) { |
|
| 559 | - if ( ! empty( $word ) && strlen( $word ) > 1 ) { |
|
| 558 | + foreach ($words as $word) { |
|
| 559 | + if (!empty($word) && strlen($word) > 1) { |
|
| 560 | 560 | // Keep the same key for each filter |
| 561 | 561 | $filter['value'] = $word; |
| 562 | 562 | // Add a search for the value |
@@ -571,25 +571,25 @@ discard block |
||
| 571 | 571 | |
| 572 | 572 | case 'date': |
| 573 | 573 | |
| 574 | - if ( is_array( $value ) ) { |
|
| 574 | + if (is_array($value)) { |
|
| 575 | 575 | |
| 576 | 576 | // Reset filter variable |
| 577 | 577 | $filter = array(); |
| 578 | 578 | |
| 579 | - foreach ( $value as $k => $date ) { |
|
| 580 | - if ( empty( $date ) ) { |
|
| 579 | + foreach ($value as $k => $date) { |
|
| 580 | + if (empty($date)) { |
|
| 581 | 581 | continue; |
| 582 | 582 | } |
| 583 | 583 | $operator = 'start' === $k ? '>' : '<'; |
| 584 | 584 | |
| 585 | 585 | $filter[] = array( |
| 586 | 586 | 'key' => $field_id, |
| 587 | - 'value' => self::get_formatted_date( $date, 'Y-m-d' ), |
|
| 587 | + 'value' => self::get_formatted_date($date, 'Y-m-d'), |
|
| 588 | 588 | 'operator' => $operator, |
| 589 | 589 | ); |
| 590 | 590 | } |
| 591 | 591 | } else { |
| 592 | - $filter['value'] = self::get_formatted_date( $value, 'Y-m-d' ); |
|
| 592 | + $filter['value'] = self::get_formatted_date($value, 'Y-m-d'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | break; |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * |
| 609 | 609 | * @return string Format of the date in the database |
| 610 | 610 | */ |
| 611 | - public static function get_date_field_format( GF_Field_Date $field ) { |
|
| 611 | + public static function get_date_field_format(GF_Field_Date $field) { |
|
| 612 | 612 | $format = 'm/d/Y'; |
| 613 | 613 | $datepicker = array( |
| 614 | 614 | 'mdy' => 'm/d/Y', |
@@ -620,8 +620,8 @@ discard block |
||
| 620 | 620 | 'ymd_dot' => 'Y.m.d', |
| 621 | 621 | ); |
| 622 | 622 | |
| 623 | - if ( ! empty( $field->dateFormat ) && isset( $datepicker[ $field->dateFormat ] ) ){ |
|
| 624 | - $format = $datepicker[ $field->dateFormat ]; |
|
| 623 | + if (!empty($field->dateFormat) && isset($datepicker[$field->dateFormat])) { |
|
| 624 | + $format = $datepicker[$field->dateFormat]; |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | return $format; |
@@ -634,13 +634,13 @@ discard block |
||
| 634 | 634 | * @param string $format Wanted formatted date |
| 635 | 635 | * @return string |
| 636 | 636 | */ |
| 637 | - public static function get_formatted_date( $value = '', $format = 'Y-m-d' ) { |
|
| 638 | - $date = date_create( $value ); |
|
| 639 | - if ( empty( $date ) ) { |
|
| 640 | - do_action( 'gravityview_log_debug', sprintf( '%s[get_formatted_date] Date format not valid: ', get_class( self::$instance ) ), $value ); |
|
| 637 | + public static function get_formatted_date($value = '', $format = 'Y-m-d') { |
|
| 638 | + $date = date_create($value); |
|
| 639 | + if (empty($date)) { |
|
| 640 | + do_action('gravityview_log_debug', sprintf('%s[get_formatted_date] Date format not valid: ', get_class(self::$instance)), $value); |
|
| 641 | 641 | return ''; |
| 642 | 642 | } |
| 643 | - return $date->format( $format ); |
|
| 643 | + return $date->format($format); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | |
@@ -648,10 +648,10 @@ discard block |
||
| 648 | 648 | * Include this extension templates path |
| 649 | 649 | * @param array $file_paths List of template paths ordered |
| 650 | 650 | */ |
| 651 | - public function add_template_path( $file_paths ) { |
|
| 651 | + public function add_template_path($file_paths) { |
|
| 652 | 652 | |
| 653 | 653 | // Index 100 is the default GravityView template path. |
| 654 | - $file_paths[102] = self::$file . 'templates/'; |
|
| 654 | + $file_paths[102] = self::$file.'templates/'; |
|
| 655 | 655 | |
| 656 | 656 | return $file_paths; |
| 657 | 657 | } |
@@ -663,50 +663,50 @@ discard block |
||
| 663 | 663 | * @param type $context |
| 664 | 664 | * @return type |
| 665 | 665 | */ |
| 666 | - public function render_frontend( $widget_args, $content = '', $context = '' ) { |
|
| 666 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
| 667 | 667 | /** @var GravityView_View $gravityview_view */ |
| 668 | 668 | $gravityview_view = GravityView_View::getInstance(); |
| 669 | 669 | |
| 670 | - if ( empty( $gravityview_view ) ) { |
|
| 671 | - do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class( $this ) ) ); |
|
| 670 | + if (empty($gravityview_view)) { |
|
| 671 | + do_action('gravityview_log_debug', sprintf('%s[render_frontend]: $gravityview_view not instantiated yet.', get_class($this))); |
|
| 672 | 672 | return; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | // get configured search fields |
| 676 | - $search_fields = ! empty( $widget_args['search_fields'] ) ? json_decode( $widget_args['search_fields'], true ) : ''; |
|
| 676 | + $search_fields = !empty($widget_args['search_fields']) ? json_decode($widget_args['search_fields'], true) : ''; |
|
| 677 | 677 | |
| 678 | - if ( empty( $search_fields ) || ! is_array( $search_fields ) ) { |
|
| 679 | - do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend] No search fields configured for widget:', get_class( $this ) ), $widget_args ); |
|
| 678 | + if (empty($search_fields) || !is_array($search_fields)) { |
|
| 679 | + do_action('gravityview_log_debug', sprintf('%s[render_frontend] No search fields configured for widget:', get_class($this)), $widget_args); |
|
| 680 | 680 | return; |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | $has_date = false; |
| 684 | 684 | |
| 685 | 685 | // prepare fields |
| 686 | - foreach ( $search_fields as $k => $field ) { |
|
| 686 | + foreach ($search_fields as $k => $field) { |
|
| 687 | 687 | |
| 688 | 688 | $updated_field = $field; |
| 689 | 689 | |
| 690 | - if ( in_array( $field['input'], array( 'date', 'date_range' ) ) ) { |
|
| 690 | + if (in_array($field['input'], array('date', 'date_range'))) { |
|
| 691 | 691 | $has_date = true; |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - $updated_field = $this->get_search_filter_details( $updated_field ); |
|
| 694 | + $updated_field = $this->get_search_filter_details($updated_field); |
|
| 695 | 695 | |
| 696 | - switch ( $field['field'] ) { |
|
| 696 | + switch ($field['field']) { |
|
| 697 | 697 | |
| 698 | 698 | case 'search_all': |
| 699 | 699 | $updated_field['key'] = 'search_all'; |
| 700 | 700 | $updated_field['input'] = 'search_all'; |
| 701 | - $updated_field['value'] = esc_attr( stripslashes_deep( rgget( 'gv_search' ) ) ); |
|
| 701 | + $updated_field['value'] = esc_attr(stripslashes_deep(rgget('gv_search'))); |
|
| 702 | 702 | break; |
| 703 | 703 | |
| 704 | 704 | case 'entry_date': |
| 705 | 705 | $updated_field['key'] = 'entry_date'; |
| 706 | 706 | $updated_field['input'] = 'entry_date'; |
| 707 | 707 | $updated_field['value'] = array( |
| 708 | - 'start' => esc_attr( stripslashes_deep( rgget( 'gv_start' ) ) ), |
|
| 709 | - 'end' => esc_attr( stripslashes_deep( rgget( 'gv_end' ) ) ), |
|
| 708 | + 'start' => esc_attr(stripslashes_deep(rgget('gv_start'))), |
|
| 709 | + 'end' => esc_attr(stripslashes_deep(rgget('gv_end'))), |
|
| 710 | 710 | ); |
| 711 | 711 | $has_date = true; |
| 712 | 712 | break; |
@@ -714,21 +714,21 @@ discard block |
||
| 714 | 714 | case 'entry_id': |
| 715 | 715 | $updated_field['key'] = 'entry_id'; |
| 716 | 716 | $updated_field['input'] = 'entry_id'; |
| 717 | - $updated_field['value'] = esc_attr( stripslashes_deep( rgget( 'gv_id' ) ) ); |
|
| 717 | + $updated_field['value'] = esc_attr(stripslashes_deep(rgget('gv_id'))); |
|
| 718 | 718 | break; |
| 719 | 719 | |
| 720 | 720 | case 'created_by': |
| 721 | 721 | $updated_field['key'] = 'created_by'; |
| 722 | 722 | $updated_field['name'] = 'gv_by'; |
| 723 | - $updated_field['value'] = esc_attr( stripslashes_deep( rgget( 'gv_by' ) ) ); |
|
| 723 | + $updated_field['value'] = esc_attr(stripslashes_deep(rgget('gv_by'))); |
|
| 724 | 724 | $updated_field['choices'] = self::get_created_by_choices(); |
| 725 | 725 | break; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - $search_fields[ $k ] = $updated_field; |
|
| 728 | + $search_fields[$k] = $updated_field; |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend] Calculated Search Fields: ', get_class( $this ) ), $search_fields ); |
|
| 731 | + do_action('gravityview_log_debug', sprintf('%s[render_frontend] Calculated Search Fields: ', get_class($this)), $search_fields); |
|
| 732 | 732 | |
| 733 | 733 | /** |
| 734 | 734 | * @filter `gravityview_widget_search_filters` Modify what fields are shown. The order of the fields in the $search_filters array controls the order as displayed in the search bar widget. |
@@ -737,25 +737,25 @@ discard block |
||
| 737 | 737 | * @param array $widget_args Args passed to this method. {@since 1.8} |
| 738 | 738 | * @var array |
| 739 | 739 | */ |
| 740 | - $gravityview_view->search_fields = apply_filters( 'gravityview_widget_search_filters', $search_fields, $this, $widget_args ); |
|
| 740 | + $gravityview_view->search_fields = apply_filters('gravityview_widget_search_filters', $search_fields, $this, $widget_args); |
|
| 741 | 741 | |
| 742 | - $gravityview_view->search_layout = ! empty( $widget_args['search_layout'] ) ? $widget_args['search_layout'] : 'horizontal'; |
|
| 742 | + $gravityview_view->search_layout = !empty($widget_args['search_layout']) ? $widget_args['search_layout'] : 'horizontal'; |
|
| 743 | 743 | |
| 744 | 744 | /** @since 1.14 */ |
| 745 | - $gravityview_view->search_mode = ! empty( $widget_args['search_mode'] ) ? $widget_args['search_mode'] : 'any'; |
|
| 745 | + $gravityview_view->search_mode = !empty($widget_args['search_mode']) ? $widget_args['search_mode'] : 'any'; |
|
| 746 | 746 | |
| 747 | - $custom_class = ! empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : ''; |
|
| 747 | + $custom_class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
| 748 | 748 | |
| 749 | - $gravityview_view->search_class = self::get_search_class( $custom_class ); |
|
| 749 | + $gravityview_view->search_class = self::get_search_class($custom_class); |
|
| 750 | 750 | |
| 751 | - $gravityview_view->search_clear = ! empty( $widget_args['search_clear'] ) ? $widget_args['search_clear'] : false; |
|
| 751 | + $gravityview_view->search_clear = !empty($widget_args['search_clear']) ? $widget_args['search_clear'] : false; |
|
| 752 | 752 | |
| 753 | - if ( $has_date ) { |
|
| 753 | + if ($has_date) { |
|
| 754 | 754 | // enqueue datepicker stuff only if needed! |
| 755 | 755 | $this->enqueue_datepicker(); |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - $gravityview_view->render( 'widget', 'search', false ); |
|
| 758 | + $gravityview_view->render('widget', 'search', false); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -765,12 +765,12 @@ discard block |
||
| 765 | 765 | * |
| 766 | 766 | * @return string Sanitized CSS class for the search form |
| 767 | 767 | */ |
| 768 | - public static function get_search_class( $custom_class = '' ) { |
|
| 768 | + public static function get_search_class($custom_class = '') { |
|
| 769 | 769 | $gravityview_view = GravityView_View::getInstance(); |
| 770 | 770 | |
| 771 | 771 | $search_class = 'gv-search-'.$gravityview_view->search_layout; |
| 772 | 772 | |
| 773 | - if ( ! empty( $custom_class ) ) { |
|
| 773 | + if (!empty($custom_class)) { |
|
| 774 | 774 | $search_class .= ' '.$custom_class; |
| 775 | 775 | } |
| 776 | 776 | |
@@ -779,12 +779,12 @@ discard block |
||
| 779 | 779 | * |
| 780 | 780 | * @param string $search_class The CSS class for the search form |
| 781 | 781 | */ |
| 782 | - $search_class = apply_filters( 'gravityview_search_class', $search_class ); |
|
| 782 | + $search_class = apply_filters('gravityview_search_class', $search_class); |
|
| 783 | 783 | |
| 784 | 784 | // Is there an active search being performed? Used by fe-views.js |
| 785 | 785 | $search_class .= GravityView_frontend::getInstance()->isSearch() ? ' gv-is-search' : ''; |
| 786 | 786 | |
| 787 | - return gravityview_sanitize_html_class( $search_class ); |
|
| 787 | + return gravityview_sanitize_html_class($search_class); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | |
@@ -799,9 +799,9 @@ discard block |
||
| 799 | 799 | |
| 800 | 800 | $post_id = $gravityview_view->getPostId() ? $gravityview_view->getPostId() : $gravityview_view->getViewId(); |
| 801 | 801 | |
| 802 | - $url = add_query_arg( array(), get_permalink( $post_id ) ); |
|
| 802 | + $url = add_query_arg(array(), get_permalink($post_id)); |
|
| 803 | 803 | |
| 804 | - return esc_url( $url ); |
|
| 804 | + return esc_url($url); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | /** |
@@ -810,42 +810,42 @@ discard block |
||
| 810 | 810 | * @param array $form_field Form field data, as fetched by `gravityview_get_field()` |
| 811 | 811 | * @return string Label for the search form |
| 812 | 812 | */ |
| 813 | - private static function get_field_label( $field, $form_field = array() ) { |
|
| 813 | + private static function get_field_label($field, $form_field = array()) { |
|
| 814 | 814 | |
| 815 | - $label = rgget( 'label', $field ); |
|
| 815 | + $label = rgget('label', $field); |
|
| 816 | 816 | |
| 817 | - if( '' === $label ) { |
|
| 817 | + if ('' === $label) { |
|
| 818 | 818 | |
| 819 | - $label = isset( $form_field['label'] ) ? $form_field['label'] : ''; |
|
| 819 | + $label = isset($form_field['label']) ? $form_field['label'] : ''; |
|
| 820 | 820 | |
| 821 | - switch( $field['field'] ) { |
|
| 821 | + switch ($field['field']) { |
|
| 822 | 822 | case 'search_all': |
| 823 | - $label = __( 'Search Entries:', 'gravityview' ); |
|
| 823 | + $label = __('Search Entries:', 'gravityview'); |
|
| 824 | 824 | break; |
| 825 | 825 | case 'entry_date': |
| 826 | - $label = __( 'Filter by date:', 'gravityview' ); |
|
| 826 | + $label = __('Filter by date:', 'gravityview'); |
|
| 827 | 827 | break; |
| 828 | 828 | case 'entry_id': |
| 829 | - $label = __( 'Entry ID:', 'gravityview' ); |
|
| 829 | + $label = __('Entry ID:', 'gravityview'); |
|
| 830 | 830 | break; |
| 831 | 831 | case 'created_by': |
| 832 | - $label = __( 'Submitted by:', 'gravityview' ); |
|
| 832 | + $label = __('Submitted by:', 'gravityview'); |
|
| 833 | 833 | break; |
| 834 | 834 | case 'is_fulfilled': |
| 835 | - $label = __( 'Is Fulfilled', 'gravityview' ); |
|
| 835 | + $label = __('Is Fulfilled', 'gravityview'); |
|
| 836 | 836 | break; |
| 837 | 837 | default: |
| 838 | 838 | // If this is a field input, not a field |
| 839 | - if ( strpos( $field['field'], '.' ) > 0 && ! empty( $form_field['inputs'] ) ) { |
|
| 839 | + if (strpos($field['field'], '.') > 0 && !empty($form_field['inputs'])) { |
|
| 840 | 840 | |
| 841 | 841 | // Get the label for the field in question, which returns an array |
| 842 | - $items = wp_list_filter( $form_field['inputs'], array( 'id' => $field['field'] ) ); |
|
| 842 | + $items = wp_list_filter($form_field['inputs'], array('id' => $field['field'])); |
|
| 843 | 843 | |
| 844 | 844 | // Get the item with the `label` key |
| 845 | - $values = wp_list_pluck( $items, 'label' ); |
|
| 845 | + $values = wp_list_pluck($items, 'label'); |
|
| 846 | 846 | |
| 847 | 847 | // There will only one item in the array, but this is easier |
| 848 | - foreach ( $values as $value ) { |
|
| 848 | + foreach ($values as $value) { |
|
| 849 | 849 | $label = $value; |
| 850 | 850 | break; |
| 851 | 851 | } |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | * @param[in,out] string $label Existing label text, sanitized. |
| 859 | 859 | * @param[in] array $form_field Gravity Forms field array, as returned by `GFFormsModel::get_field()` |
| 860 | 860 | */ |
| 861 | - $label = apply_filters( 'gravityview_search_field_label', esc_attr( $label ), $form_field ); |
|
| 861 | + $label = apply_filters('gravityview_search_field_label', esc_attr($label), $form_field); |
|
| 862 | 862 | |
| 863 | 863 | return $label; |
| 864 | 864 | } |
@@ -869,39 +869,39 @@ discard block |
||
| 869 | 869 | * @param array $field |
| 870 | 870 | * @return array |
| 871 | 871 | */ |
| 872 | - private function get_search_filter_details( $field ) { |
|
| 872 | + private function get_search_filter_details($field) { |
|
| 873 | 873 | |
| 874 | 874 | $gravityview_view = GravityView_View::getInstance(); |
| 875 | 875 | |
| 876 | 876 | $form = $gravityview_view->getForm(); |
| 877 | 877 | |
| 878 | 878 | // for advanced field ids (eg, first name / last name ) |
| 879 | - $name = 'filter_' . str_replace( '.', '_', $field['field'] ); |
|
| 879 | + $name = 'filter_'.str_replace('.', '_', $field['field']); |
|
| 880 | 880 | |
| 881 | 881 | // get searched value from $_GET (string or array) |
| 882 | - $value = rgget( $name ); |
|
| 882 | + $value = rgget($name); |
|
| 883 | 883 | |
| 884 | 884 | // get form field details |
| 885 | - $form_field = gravityview_get_field( $form, $field['field'] ); |
|
| 885 | + $form_field = gravityview_get_field($form, $field['field']); |
|
| 886 | 886 | |
| 887 | 887 | $filter = array( |
| 888 | 888 | 'key' => $field['field'], |
| 889 | 889 | 'name' => $name, |
| 890 | - 'label' => self::get_field_label( $field, $form_field ), |
|
| 890 | + 'label' => self::get_field_label($field, $form_field), |
|
| 891 | 891 | 'input' => $field['input'], |
| 892 | 892 | 'value' => $value, |
| 893 | 893 | 'type' => $form_field['type'], |
| 894 | 894 | ); |
| 895 | 895 | |
| 896 | 896 | // collect choices |
| 897 | - if ( 'post_category' === $form_field['type'] && ! empty( $form_field['displayAllCategories'] ) && empty( $form_field['choices'] ) ) { |
|
| 897 | + if ('post_category' === $form_field['type'] && !empty($form_field['displayAllCategories']) && empty($form_field['choices'])) { |
|
| 898 | 898 | $filter['choices'] = self::get_post_categories_choices(); |
| 899 | - } elseif ( ! empty( $form_field['choices'] ) ) { |
|
| 899 | + } elseif (!empty($form_field['choices'])) { |
|
| 900 | 900 | $filter['choices'] = $form_field['choices']; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | - if ( 'date_range' === $field['input'] && empty( $value ) ) { |
|
| 904 | - $filter['value'] = array( 'start' => '', 'end' => '' ); |
|
| 903 | + if ('date_range' === $field['input'] && empty($value)) { |
|
| 904 | + $filter['value'] = array('start' => '', 'end' => ''); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | return $filter; |
@@ -921,10 +921,10 @@ discard block |
||
| 921 | 921 | * filter gravityview/get_users/search_widget |
| 922 | 922 | * @see \GVCommon::get_users |
| 923 | 923 | */ |
| 924 | - $users = GVCommon::get_users( 'search_widget', array( 'fields' => array( 'ID', 'display_name' ) ) ); |
|
| 924 | + $users = GVCommon::get_users('search_widget', array('fields' => array('ID', 'display_name'))); |
|
| 925 | 925 | |
| 926 | 926 | $choices = array(); |
| 927 | - foreach ( $users as $user ) { |
|
| 927 | + foreach ($users as $user) { |
|
| 928 | 928 | $choices[] = array( |
| 929 | 929 | 'value' => $user->ID, |
| 930 | 930 | 'text' => $user->display_name, |
@@ -945,16 +945,16 @@ discard block |
||
| 945 | 945 | 'hierarchical' => 1, |
| 946 | 946 | 'taxonomy' => 'category', |
| 947 | 947 | ); |
| 948 | - $categories = get_categories( $args ); |
|
| 948 | + $categories = get_categories($args); |
|
| 949 | 949 | |
| 950 | - if ( empty( $categories ) ) { |
|
| 950 | + if (empty($categories)) { |
|
| 951 | 951 | return array(); |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | $choices = array(); |
| 955 | 955 | |
| 956 | - foreach ( $categories as $category ) { |
|
| 957 | - $choices[] = array( 'text' => $category->name, 'value' => $category->term_id ); |
|
| 956 | + foreach ($categories as $category) { |
|
| 957 | + $choices[] = array('text' => $category->name, 'value' => $category->term_id); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | return $choices; |
@@ -968,11 +968,11 @@ discard block |
||
| 968 | 968 | public static function the_clear_search_button() { |
| 969 | 969 | $gravityview_view = GravityView_View::getInstance(); |
| 970 | 970 | |
| 971 | - if ( $gravityview_view->search_clear ) { |
|
| 971 | + if ($gravityview_view->search_clear) { |
|
| 972 | 972 | |
| 973 | - $url = strtok( add_query_arg( array() ), '?' ); |
|
| 973 | + $url = strtok(add_query_arg(array()), '?'); |
|
| 974 | 974 | |
| 975 | - echo gravityview_get_link( $url, esc_html__( 'Clear', 'gravityview' ), 'class=button gv-search-clear' ); |
|
| 975 | + echo gravityview_get_link($url, esc_html__('Clear', 'gravityview'), 'class=button gv-search-clear'); |
|
| 976 | 976 | |
| 977 | 977 | } |
| 978 | 978 | } |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | * Require the datepicker script for the frontend GV script |
| 984 | 984 | * @param array $js_dependencies Array of existing required scripts for the fe-views.js script |
| 985 | 985 | */ |
| 986 | - public function add_datepicker_js_dependency( $js_dependencies ) { |
|
| 986 | + public function add_datepicker_js_dependency($js_dependencies) { |
|
| 987 | 987 | |
| 988 | 988 | $js_dependencies[] = 'jquery-ui-datepicker'; |
| 989 | 989 | |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | * |
| 999 | 999 | * @return array |
| 1000 | 1000 | */ |
| 1001 | - public function add_datepicker_localization( $localizations = array(), $view_data = array() ) { |
|
| 1001 | + public function add_datepicker_localization($localizations = array(), $view_data = array()) { |
|
| 1002 | 1002 | global $wp_locale; |
| 1003 | 1003 | |
| 1004 | 1004 | /** |
@@ -1008,26 +1008,26 @@ discard block |
||
| 1008 | 1008 | * @param array $js_localization The data padded to the Javascript file |
| 1009 | 1009 | * @param array $view_data View data array with View settings |
| 1010 | 1010 | */ |
| 1011 | - $datepicker_settings = apply_filters( 'gravityview_datepicker_settings', array( |
|
| 1011 | + $datepicker_settings = apply_filters('gravityview_datepicker_settings', array( |
|
| 1012 | 1012 | 'yearRange' => '-5:+5', |
| 1013 | 1013 | 'changeMonth' => true, |
| 1014 | 1014 | 'changeYear' => true, |
| 1015 | - 'closeText' => esc_attr_x( 'Close', 'Close calendar', 'gravityview' ), |
|
| 1016 | - 'prevText' => esc_attr_x( 'Prev', 'Previous month in calendar', 'gravityview' ), |
|
| 1017 | - 'nextText' => esc_attr_x( 'Next', 'Next month in calendar', 'gravityview' ), |
|
| 1018 | - 'currentText' => esc_attr_x( 'Today', 'Today in calendar', 'gravityview' ), |
|
| 1019 | - 'weekHeader' => esc_attr_x( 'Week', 'Week in calendar', 'gravityview' ), |
|
| 1020 | - 'monthStatus' => __( 'Show a different month', 'gravityview' ), |
|
| 1021 | - 'monthNames' => array_values( $wp_locale->month ), |
|
| 1022 | - 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), |
|
| 1023 | - 'dayNames' => array_values( $wp_locale->weekday ), |
|
| 1024 | - 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ), |
|
| 1025 | - 'dayNamesMin' => array_values( $wp_locale->weekday_initial ), |
|
| 1015 | + 'closeText' => esc_attr_x('Close', 'Close calendar', 'gravityview'), |
|
| 1016 | + 'prevText' => esc_attr_x('Prev', 'Previous month in calendar', 'gravityview'), |
|
| 1017 | + 'nextText' => esc_attr_x('Next', 'Next month in calendar', 'gravityview'), |
|
| 1018 | + 'currentText' => esc_attr_x('Today', 'Today in calendar', 'gravityview'), |
|
| 1019 | + 'weekHeader' => esc_attr_x('Week', 'Week in calendar', 'gravityview'), |
|
| 1020 | + 'monthStatus' => __('Show a different month', 'gravityview'), |
|
| 1021 | + 'monthNames' => array_values($wp_locale->month), |
|
| 1022 | + 'monthNamesShort' => array_values($wp_locale->month_abbrev), |
|
| 1023 | + 'dayNames' => array_values($wp_locale->weekday), |
|
| 1024 | + 'dayNamesShort' => array_values($wp_locale->weekday_abbrev), |
|
| 1025 | + 'dayNamesMin' => array_values($wp_locale->weekday_initial), |
|
| 1026 | 1026 | // get the start of week from WP general setting |
| 1027 | - 'firstDay' => get_option( 'start_of_week' ), |
|
| 1027 | + 'firstDay' => get_option('start_of_week'), |
|
| 1028 | 1028 | // is Right to left language? default is false |
| 1029 | 1029 | 'isRTL' => is_rtl(), |
| 1030 | - ), $view_data ); |
|
| 1030 | + ), $view_data); |
|
| 1031 | 1031 | |
| 1032 | 1032 | $localizations['datepicker'] = $datepicker_settings; |
| 1033 | 1033 | |
@@ -1046,13 +1046,13 @@ discard block |
||
| 1046 | 1046 | public function enqueue_datepicker() { |
| 1047 | 1047 | $gravityview_view = GravityView_View::getInstance(); |
| 1048 | 1048 | |
| 1049 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 1049 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 1050 | 1050 | |
| 1051 | - add_filter( 'gravityview_js_dependencies', array( $this, 'add_datepicker_js_dependency' ) ); |
|
| 1052 | - add_filter( 'gravityview_js_localization', array( $this, 'add_datepicker_localization' ), 10, 2 ); |
|
| 1051 | + add_filter('gravityview_js_dependencies', array($this, 'add_datepicker_js_dependency')); |
|
| 1052 | + add_filter('gravityview_js_localization', array($this, 'add_datepicker_localization'), 10, 2); |
|
| 1053 | 1053 | |
| 1054 | 1054 | $scheme = is_ssl() ? 'https://' : 'http://'; |
| 1055 | - wp_enqueue_style( 'jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css' ); |
|
| 1055 | + wp_enqueue_style('jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css'); |
|
| 1056 | 1056 | |
| 1057 | 1057 | /** |
| 1058 | 1058 | * @filter `gravityview_search_datepicker_class` |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | * - `ymd_dash` (yyyy-mm-dd) |
| 1068 | 1068 | * - `ymp_dot` (yyyy.mm.dd) |
| 1069 | 1069 | */ |
| 1070 | - $datepicker_class = apply_filters( 'gravityview_search_datepicker_class', 'gv-datepicker datepicker mdy' ); |
|
| 1070 | + $datepicker_class = apply_filters('gravityview_search_datepicker_class', 'gv-datepicker datepicker mdy'); |
|
| 1071 | 1071 | |
| 1072 | 1072 | $gravityview_view->datepicker_class = $datepicker_class; |
| 1073 | 1073 | |
@@ -176,6 +176,7 @@ |
||
| 176 | 176 | * Get the entries that will be shown in the current widget |
| 177 | 177 | * |
| 178 | 178 | * @param array $instance Settings for the current widget |
| 179 | + * @param string $form_id |
|
| 179 | 180 | * |
| 180 | 181 | * @return array $entries Multidimensional array of Gravity Forms entries |
| 181 | 182 | */ |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @file class-gravityview-recent-entries-widget.php |
|
| 4 | - */ |
|
| 3 | + * @file class-gravityview-recent-entries-widget.php |
|
| 4 | + */ |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Class GravityView_Recent_Entries_Widget |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | // Get the settings for the View ID |
| 185 | 185 | $view_settings = gravityview_get_template_settings( $instance['view_id'] ); |
| 186 | 186 | |
| 187 | - // Set the context view ID to avoid conflicts with the Advanced Filter extension. |
|
| 188 | - $criteria['context_view_id'] = $instance['view_id']; |
|
| 187 | + // Set the context view ID to avoid conflicts with the Advanced Filter extension. |
|
| 188 | + $criteria['context_view_id'] = $instance['view_id']; |
|
| 189 | 189 | |
| 190 | 190 | $instance['limit'] = isset( $instance['limit'] ) ? $instance['limit'] : 10; |
| 191 | 191 | $view_settings['id'] = $instance['view_id']; |
@@ -15,19 +15,19 @@ discard block |
||
| 15 | 15 | $name = __('GravityView Recent Entries', 'gravityview'); |
| 16 | 16 | |
| 17 | 17 | $widget_options = array( |
| 18 | - 'description' => __( 'Display the most recent entries for a View', 'gravityview' ), |
|
| 18 | + 'description' => __('Display the most recent entries for a View', 'gravityview'), |
|
| 19 | 19 | ); |
| 20 | 20 | |
| 21 | - parent::__construct( 'gv_recent_entries', $name, $widget_options ); |
|
| 21 | + parent::__construct('gv_recent_entries', $name, $widget_options); |
|
| 22 | 22 | |
| 23 | 23 | $this->initialize(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | private function initialize() { |
| 27 | 27 | |
| 28 | - add_action('admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts') ); |
|
| 28 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); |
|
| 29 | 29 | |
| 30 | - add_action( 'wp_ajax_gv_get_view_merge_tag_data', array( $this, 'ajax_get_view_merge_tag_data' ) ); |
|
| 30 | + add_action('wp_ajax_gv_get_view_merge_tag_data', array($this, 'ajax_get_view_merge_tag_data')); |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function ajax_get_view_merge_tag_data() { |
| 40 | 40 | |
| 41 | - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gravityview_ajax_widget' ) ) { |
|
| 42 | - exit( false ); |
|
| 41 | + if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajax_widget')) { |
|
| 42 | + exit(false); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $form_id = gravityview_get_form_id( $_POST['view_id'] ); |
|
| 45 | + $form_id = gravityview_get_form_id($_POST['view_id']); |
|
| 46 | 46 | |
| 47 | - $form = RGFormsModel::get_form_meta( $form_id ); |
|
| 47 | + $form = RGFormsModel::get_form_meta($form_id); |
|
| 48 | 48 | |
| 49 | 49 | $output = array( |
| 50 | 50 | 'form' => array( |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | 'title' => $form['title'], |
| 53 | 53 | 'fields' => $form['fields'], |
| 54 | 54 | ), |
| 55 | - 'mergeTags' => GFCommon::get_merge_tags( $form['fields'], '', false ), |
|
| 55 | + 'mergeTags' => GFCommon::get_merge_tags($form['fields'], '', false), |
|
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - echo json_encode( $output ); |
|
| 58 | + echo json_encode($output); |
|
| 59 | 59 | |
| 60 | 60 | exit; |
| 61 | 61 | } |
@@ -68,19 +68,19 @@ discard block |
||
| 68 | 68 | function admin_enqueue_scripts() { |
| 69 | 69 | global $pagenow; |
| 70 | 70 | |
| 71 | - if( $pagenow === 'widgets.php' ) { |
|
| 71 | + if ($pagenow === 'widgets.php') { |
|
| 72 | 72 | |
| 73 | 73 | $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
| 74 | 74 | |
| 75 | 75 | GravityView_Admin_Views::enqueue_gravity_forms_scripts(); |
| 76 | 76 | |
| 77 | - wp_enqueue_script( 'gravityview_widgets', plugins_url('assets/js/admin-widgets'.$script_debug.'.js', GRAVITYVIEW_FILE), array( 'jquery', 'gform_gravityforms' ), GravityView_Plugin::version ); |
|
| 77 | + wp_enqueue_script('gravityview_widgets', plugins_url('assets/js/admin-widgets'.$script_debug.'.js', GRAVITYVIEW_FILE), array('jquery', 'gform_gravityforms'), GravityView_Plugin::version); |
|
| 78 | 78 | |
| 79 | - wp_localize_script( 'gravityview_widgets', 'GVWidgets', array( |
|
| 80 | - 'nonce' => wp_create_nonce( 'gravityview_ajax_widget' ) |
|
| 79 | + wp_localize_script('gravityview_widgets', 'GVWidgets', array( |
|
| 80 | + 'nonce' => wp_create_nonce('gravityview_ajax_widget') |
|
| 81 | 81 | )); |
| 82 | 82 | |
| 83 | - wp_enqueue_style( 'gravityview_views_styles', plugins_url('assets/css/admin-views.css', GRAVITYVIEW_FILE), array('dashicons' ), GravityView_Plugin::version ); |
|
| 83 | + wp_enqueue_style('gravityview_views_styles', plugins_url('assets/css/admin-views.css', GRAVITYVIEW_FILE), array('dashicons'), GravityView_Plugin::version); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | } |
@@ -92,22 +92,22 @@ discard block |
||
| 92 | 92 | * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. |
| 93 | 93 | * @param array $instance The settings for the particular instance of the widget. |
| 94 | 94 | */ |
| 95 | - function widget( $args, $instance ) { |
|
| 95 | + function widget($args, $instance) { |
|
| 96 | 96 | |
| 97 | 97 | // Don't have the Customizer render too soon. |
| 98 | - if( empty( $instance['view_id'] ) ) { |
|
| 98 | + if (empty($instance['view_id'])) { |
|
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $args['id'] = ( isset( $args['id'] ) ) ? $args['id'] : 'gv_recent_entries'; |
|
| 103 | - $instance['title'] = ( isset( $instance['title'] ) ) ? $instance['title'] : ''; |
|
| 102 | + $args['id'] = (isset($args['id'])) ? $args['id'] : 'gv_recent_entries'; |
|
| 103 | + $instance['title'] = (isset($instance['title'])) ? $instance['title'] : ''; |
|
| 104 | 104 | |
| 105 | - $title = apply_filters( 'widget_title', $instance[ 'title' ], $instance, $args['id'] ); |
|
| 105 | + $title = apply_filters('widget_title', $instance['title'], $instance, $args['id']); |
|
| 106 | 106 | |
| 107 | 107 | echo $args['before_widget']; |
| 108 | 108 | |
| 109 | - if ( !empty( $title ) ) { |
|
| 110 | - echo $args['before_title'] . $title . $args['after_title']; |
|
| 109 | + if (!empty($title)) { |
|
| 110 | + echo $args['before_title'].$title.$args['after_title']; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -115,17 +115,17 @@ discard block |
||
| 115 | 115 | * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. |
| 116 | 116 | * @param array $instance The settings for the particular instance of the widget. |
| 117 | 117 | */ |
| 118 | - do_action( 'gravityview/widget/recent-entries/before_widget', $args, $instance ); |
|
| 118 | + do_action('gravityview/widget/recent-entries/before_widget', $args, $instance); |
|
| 119 | 119 | |
| 120 | 120 | // Print the entry list |
| 121 | - echo $this->get_output( $instance ); |
|
| 121 | + echo $this->get_output($instance); |
|
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * @action `gravityview/widget/recent-entries/after_widget` After recent entries are displayed in the WordPress widget |
| 125 | 125 | * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. |
| 126 | 126 | * @param array $instance The settings for the particular instance of the widget. |
| 127 | 127 | */ |
| 128 | - do_action( 'gravityview/widget/recent-entries/after_widget', $args, $instance ); |
|
| 128 | + do_action('gravityview/widget/recent-entries/after_widget', $args, $instance); |
|
| 129 | 129 | |
| 130 | 130 | echo $args['after_widget']; |
| 131 | 131 | } |
@@ -139,25 +139,25 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - private function get_output( $instance ) { |
|
| 142 | + private function get_output($instance) { |
|
| 143 | 143 | |
| 144 | - $form_id = gravityview_get_form_id( $instance['view_id'] ); |
|
| 144 | + $form_id = gravityview_get_form_id($instance['view_id']); |
|
| 145 | 145 | |
| 146 | - $form = gravityview_get_form( $form_id ); |
|
| 146 | + $form = gravityview_get_form($form_id); |
|
| 147 | 147 | |
| 148 | - $entries = $this->get_entries( $instance, $form_id ); |
|
| 148 | + $entries = $this->get_entries($instance, $form_id); |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * @since 1.6.1 |
| 152 | 152 | * @var int $entry_link_post_id The ID to use as the parent post for the entry |
| 153 | 153 | */ |
| 154 | - $entry_link_post_id = ( empty( $instance['error_post_id'] ) && !empty( $instance['post_id'] ) ) ? $instance['post_id'] : $instance['view_id']; |
|
| 154 | + $entry_link_post_id = (empty($instance['error_post_id']) && !empty($instance['post_id'])) ? $instance['post_id'] : $instance['view_id']; |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Generate list output |
| 158 | 158 | * @since 1.7.2 |
| 159 | 159 | */ |
| 160 | - $List = new GravityView_Entry_List( $entries, $entry_link_post_id, $form, $instance['link_format'], $instance['after_link'], 'recent-entries-widget' ); |
|
| 160 | + $List = new GravityView_Entry_List($entries, $entry_link_post_id, $form, $instance['link_format'], $instance['after_link'], 'recent-entries-widget'); |
|
| 161 | 161 | |
| 162 | 162 | $output = $List->get_output(); |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param string $output HTML to be displayed |
| 167 | 167 | * @param array $instance Widget settings |
| 168 | 168 | */ |
| 169 | - $output = apply_filters( 'gravityview/widget/recent-entries/output', $output, $instance ); |
|
| 169 | + $output = apply_filters('gravityview/widget/recent-entries/output', $output, $instance); |
|
| 170 | 170 | |
| 171 | 171 | return $output; |
| 172 | 172 | } |
@@ -179,15 +179,15 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return array $entries Multidimensional array of Gravity Forms entries |
| 181 | 181 | */ |
| 182 | - private function get_entries( $instance, $form_id ) { |
|
| 182 | + private function get_entries($instance, $form_id) { |
|
| 183 | 183 | |
| 184 | 184 | // Get the settings for the View ID |
| 185 | - $view_settings = gravityview_get_template_settings( $instance['view_id'] ); |
|
| 185 | + $view_settings = gravityview_get_template_settings($instance['view_id']); |
|
| 186 | 186 | |
| 187 | 187 | // Set the context view ID to avoid conflicts with the Advanced Filter extension. |
| 188 | 188 | $criteria['context_view_id'] = $instance['view_id']; |
| 189 | 189 | |
| 190 | - $instance['limit'] = isset( $instance['limit'] ) ? $instance['limit'] : 10; |
|
| 190 | + $instance['limit'] = isset($instance['limit']) ? $instance['limit'] : 10; |
|
| 191 | 191 | $view_settings['id'] = $instance['view_id']; |
| 192 | 192 | $view_settings['page_size'] = $instance['limit']; |
| 193 | 193 | |
@@ -198,16 +198,16 @@ discard block |
||
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | 200 | // Prepare Search Criteria |
| 201 | - $criteria['search_criteria'] = array( 'field_filters' => array() ); |
|
| 202 | - $criteria['search_criteria'] = GravityView_frontend::process_search_only_approved( $view_settings, $criteria['search_criteria']); |
|
| 203 | - $criteria['search_criteria']['status'] = apply_filters( 'gravityview_status', 'active', $view_settings ); |
|
| 201 | + $criteria['search_criteria'] = array('field_filters' => array()); |
|
| 202 | + $criteria['search_criteria'] = GravityView_frontend::process_search_only_approved($view_settings, $criteria['search_criteria']); |
|
| 203 | + $criteria['search_criteria']['status'] = apply_filters('gravityview_status', 'active', $view_settings); |
|
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * Modify the search parameters before the entries are fetched |
| 207 | 207 | */ |
| 208 | - $criteria = apply_filters('gravityview/widget/recent-entries/criteria', $criteria, $instance, $form_id ); |
|
| 208 | + $criteria = apply_filters('gravityview/widget/recent-entries/criteria', $criteria, $instance, $form_id); |
|
| 209 | 209 | |
| 210 | - $results = GVCommon::get_entries( $form_id, $criteria ); |
|
| 210 | + $results = GVCommon::get_entries($form_id, $criteria); |
|
| 211 | 211 | |
| 212 | 212 | return $results; |
| 213 | 213 | } |
@@ -221,28 +221,28 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return array Calculated widget settings after processing |
| 223 | 223 | */ |
| 224 | - public function update( $new_instance, $old_instance ) { |
|
| 224 | + public function update($new_instance, $old_instance) { |
|
| 225 | 225 | |
| 226 | 226 | $instance = $new_instance; |
| 227 | 227 | |
| 228 | 228 | // Force positive number |
| 229 | - $instance['limit'] = empty( $instance['limit'] ) ? 10 : absint( $instance['limit'] ); |
|
| 229 | + $instance['limit'] = empty($instance['limit']) ? 10 : absint($instance['limit']); |
|
| 230 | 230 | |
| 231 | - $instance['view_id'] = intval( $instance['view_id'] ); |
|
| 231 | + $instance['view_id'] = intval($instance['view_id']); |
|
| 232 | 232 | |
| 233 | - $instance['link_format'] = trim( rtrim( $instance['link_format'] ) ); |
|
| 233 | + $instance['link_format'] = trim(rtrim($instance['link_format'])); |
|
| 234 | 234 | |
| 235 | - $instance['link_format'] = empty( $instance['link_format'] ) ? $old_instance['link_format'] : $instance['link_format']; |
|
| 235 | + $instance['link_format'] = empty($instance['link_format']) ? $old_instance['link_format'] : $instance['link_format']; |
|
| 236 | 236 | |
| 237 | - $instance['post_id'] = empty( $instance['post_id'] ) ? '' : intval( $instance['post_id'] ); |
|
| 237 | + $instance['post_id'] = empty($instance['post_id']) ? '' : intval($instance['post_id']); |
|
| 238 | 238 | |
| 239 | - $is_valid_embed_id = GravityView_View_Data::is_valid_embed_id( $instance['post_id'], $instance['view_id'] ); |
|
| 239 | + $is_valid_embed_id = GravityView_View_Data::is_valid_embed_id($instance['post_id'], $instance['view_id']); |
|
| 240 | 240 | |
| 241 | 241 | //check if post_id is a valid post with embedded View |
| 242 | - $instance['error_post_id'] = is_wp_error( $is_valid_embed_id ) ? $is_valid_embed_id->get_error_message() : NULL; |
|
| 242 | + $instance['error_post_id'] = is_wp_error($is_valid_embed_id) ? $is_valid_embed_id->get_error_message() : NULL; |
|
| 243 | 243 | |
| 244 | 244 | // Share that the widget isn't brand new |
| 245 | - $instance['updated'] = 1; |
|
| 245 | + $instance['updated'] = 1; |
|
| 246 | 246 | |
| 247 | 247 | /** |
| 248 | 248 | * Modify the updated instance. This will allow for validating any added instance settings externally. |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @param array $new_instance Widget form settings after update |
| 252 | 252 | * @param array $old_instance Widget form settings before update |
| 253 | 253 | */ |
| 254 | - $instance = apply_filters( 'gravityview/widget/update', $instance, $new_instance, $old_instance ); |
|
| 254 | + $instance = apply_filters('gravityview/widget/update', $instance, $new_instance, $old_instance); |
|
| 255 | 255 | |
| 256 | 256 | return $instance; |
| 257 | 257 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @since 1.6 |
| 261 | 261 | * @see WP_Widget::form() |
| 262 | 262 | */ |
| 263 | - public function form( $instance ) { |
|
| 263 | + public function form($instance) { |
|
| 264 | 264 | |
| 265 | 265 | // Set up some default widget settings. |
| 266 | 266 | $defaults = array( |
@@ -272,14 +272,14 @@ discard block |
||
| 272 | 272 | 'after_link' => '' |
| 273 | 273 | ); |
| 274 | 274 | |
| 275 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
| 275 | + $instance = wp_parse_args((array)$instance, $defaults); |
|
| 276 | 276 | |
| 277 | 277 | ?> |
| 278 | 278 | |
| 279 | 279 | <!-- Title --> |
| 280 | 280 | <p> |
| 281 | - <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'gravityview' ) ?></label> |
|
| 282 | - <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> |
|
| 281 | + <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title:', 'gravityview') ?></label> |
|
| 282 | + <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" /> |
|
| 283 | 283 | </p> |
| 284 | 284 | |
| 285 | 285 | <!-- Download --> |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | 'posts_per_page' => -1, |
| 290 | 290 | 'post_status' => 'publish', |
| 291 | 291 | ); |
| 292 | - $views = get_posts( $args ); |
|
| 292 | + $views = get_posts($args); |
|
| 293 | 293 | |
| 294 | 294 | // If there are no views set up yet, we get outta here. |
| 295 | - if( empty( $views ) ) { |
|
| 296 | - echo '<div id="select_gravityview_view"><div class="wrap">'. GravityView_Post_Types::no_views_text() .'</div></div>'; |
|
| 295 | + if (empty($views)) { |
|
| 296 | + echo '<div id="select_gravityview_view"><div class="wrap">'.GravityView_Post_Types::no_views_text().'</div></div>'; |
|
| 297 | 297 | return; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -304,25 +304,25 @@ discard block |
||
| 304 | 304 | * Display errors generated for invalid embed IDs |
| 305 | 305 | * @see GravityView_View_Data::is_valid_embed_id |
| 306 | 306 | */ |
| 307 | - if( isset( $instance['updated'] ) && empty( $instance['view_id'] ) ) { |
|
| 307 | + if (isset($instance['updated']) && empty($instance['view_id'])) { |
|
| 308 | 308 | ?> |
| 309 | 309 | <div class="error inline hide-on-view-change"> |
| 310 | 310 | <p><?php esc_html_e('Please select a View to search.', 'gravityview'); ?></p> |
| 311 | 311 | </div> |
| 312 | 312 | <?php |
| 313 | - unset ( $error ); |
|
| 313 | + unset ($error); |
|
| 314 | 314 | } |
| 315 | 315 | ?> |
| 316 | 316 | |
| 317 | 317 | <p> |
| 318 | - <label for="<?php echo esc_attr( $this->get_field_id( 'view_id' ) ); ?>"><?php esc_html_e('Select a View', 'gravityview'); ?></label> |
|
| 319 | - <select class="widefat gv-recent-entries-select-view" name="<?php echo esc_attr( $this->get_field_name( 'view_id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'view_id' ) ); ?>"> |
|
| 320 | - <option value=""><?php esc_html_e( '— Select a View as Entries Source —', 'gravityview' ); ?></option> |
|
| 318 | + <label for="<?php echo esc_attr($this->get_field_id('view_id')); ?>"><?php esc_html_e('Select a View', 'gravityview'); ?></label> |
|
| 319 | + <select class="widefat gv-recent-entries-select-view" name="<?php echo esc_attr($this->get_field_name('view_id')); ?>" id="<?php echo esc_attr($this->get_field_id('view_id')); ?>"> |
|
| 320 | + <option value=""><?php esc_html_e('— Select a View as Entries Source —', 'gravityview'); ?></option> |
|
| 321 | 321 | <?php |
| 322 | 322 | |
| 323 | - foreach( $views as $view ) { |
|
| 324 | - $title = empty( $view->post_title ) ? __('(no title)', 'gravityview') : $view->post_title; |
|
| 325 | - echo '<option value="'. $view->ID .'"'.selected( absint( $instance['view_id'] ), $view->ID ).'>'. esc_html( sprintf('%s #%d', $title, $view->ID ) ) .'</option>'; |
|
| 323 | + foreach ($views as $view) { |
|
| 324 | + $title = empty($view->post_title) ? __('(no title)', 'gravityview') : $view->post_title; |
|
| 325 | + echo '<option value="'.$view->ID.'"'.selected(absint($instance['view_id']), $view->ID).'>'.esc_html(sprintf('%s #%d', $title, $view->ID)).'</option>'; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | ?> |
@@ -334,44 +334,44 @@ discard block |
||
| 334 | 334 | * Display errors generated for invalid embed IDs |
| 335 | 335 | * @see GravityView_View_Data::is_valid_embed_id |
| 336 | 336 | */ |
| 337 | - if( !empty( $instance['error_post_id'] ) ) { |
|
| 337 | + if (!empty($instance['error_post_id'])) { |
|
| 338 | 338 | ?> |
| 339 | 339 | <div class="error inline"> |
| 340 | 340 | <p><?php echo $instance['error_post_id']; ?></p> |
| 341 | 341 | </div> |
| 342 | 342 | <?php |
| 343 | - unset ( $error ); |
|
| 343 | + unset ($error); |
|
| 344 | 344 | } |
| 345 | 345 | ?> |
| 346 | 346 | |
| 347 | 347 | <p> |
| 348 | - <label for="<?php echo $this->get_field_id('post_id'); ?>"><?php esc_html_e( 'If Embedded, Page ID:', 'gravityview' ); ?></label> |
|
| 349 | - <input class="code" size="3" id="<?php echo $this->get_field_id('post_id'); ?>" name="<?php echo $this->get_field_name('post_id'); ?>" type="text" value="<?php echo esc_attr( $instance['post_id'] ); ?>" /> |
|
| 348 | + <label for="<?php echo $this->get_field_id('post_id'); ?>"><?php esc_html_e('If Embedded, Page ID:', 'gravityview'); ?></label> |
|
| 349 | + <input class="code" size="3" id="<?php echo $this->get_field_id('post_id'); ?>" name="<?php echo $this->get_field_name('post_id'); ?>" type="text" value="<?php echo esc_attr($instance['post_id']); ?>" /> |
|
| 350 | 350 | <span class="howto"><?php |
| 351 | - esc_html_e('To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.', 'gravityview' ); |
|
| 352 | - echo ' '.gravityview_get_link('http://docs.gravityview.co/article/222-the-search-widget', __('Learn more…', 'gravityview' ), 'target=_blank' ); |
|
| 351 | + esc_html_e('To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.', 'gravityview'); |
|
| 352 | + echo ' '.gravityview_get_link('http://docs.gravityview.co/article/222-the-search-widget', __('Learn more…', 'gravityview'), 'target=_blank'); |
|
| 353 | 353 | ?></span> |
| 354 | 354 | </p> |
| 355 | 355 | |
| 356 | 356 | <p> |
| 357 | - <label for="<?php echo $this->get_field_id( 'limit' ); ?>"> |
|
| 358 | - <span><?php _e( 'Number of entries to show:', 'gravityview' ); ?></span> |
|
| 357 | + <label for="<?php echo $this->get_field_id('limit'); ?>"> |
|
| 358 | + <span><?php _e('Number of entries to show:', 'gravityview'); ?></span> |
|
| 359 | 359 | </label> |
| 360 | - <input class="code" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="number" value="<?php echo intval( $instance['limit'] ); ?>" size="3" /> |
|
| 360 | + <input class="code" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="number" value="<?php echo intval($instance['limit']); ?>" size="3" /> |
|
| 361 | 361 | </p> |
| 362 | 362 | |
| 363 | 363 | <p> |
| 364 | - <label for="<?php echo $this->get_field_id( 'link_format' ); ?>"> |
|
| 365 | - <span><?php _e( 'Entry link text (required)', 'gravityview' ); ?></span> |
|
| 364 | + <label for="<?php echo $this->get_field_id('link_format'); ?>"> |
|
| 365 | + <span><?php _e('Entry link text (required)', 'gravityview'); ?></span> |
|
| 366 | 366 | </label> |
| 367 | - <input id="<?php echo $this->get_field_id( 'link_format' ); ?>" name="<?php echo $this->get_field_name( 'link_format' ); ?>" type="text" value="<?php echo esc_attr( $instance['link_format'] ); ?>" class="widefat merge-tag-support mt-position-right mt-hide_all_fields" /> |
|
| 367 | + <input id="<?php echo $this->get_field_id('link_format'); ?>" name="<?php echo $this->get_field_name('link_format'); ?>" type="text" value="<?php echo esc_attr($instance['link_format']); ?>" class="widefat merge-tag-support mt-position-right mt-hide_all_fields" /> |
|
| 368 | 368 | </p> |
| 369 | 369 | |
| 370 | 370 | <p> |
| 371 | - <label for="<?php echo $this->get_field_id( 'after_link' ); ?>"> |
|
| 372 | - <span><?php _e( 'Text or HTML to display after the link (optional)', 'gravityview' ); ?></span> |
|
| 371 | + <label for="<?php echo $this->get_field_id('after_link'); ?>"> |
|
| 372 | + <span><?php _e('Text or HTML to display after the link (optional)', 'gravityview'); ?></span> |
|
| 373 | 373 | </label> |
| 374 | - <textarea id="<?php echo $this->get_field_id( 'after_link' ); ?>" name="<?php echo $this->get_field_name( 'after_link' ); ?>" rows="5" class="widefat code merge-tag-support mt-position-right mt-hide_all_fields"><?php echo esc_textarea( $instance['after_link'] ); ?></textarea> |
|
| 374 | + <textarea id="<?php echo $this->get_field_id('after_link'); ?>" name="<?php echo $this->get_field_name('after_link'); ?>" rows="5" class="widefat code merge-tag-support mt-position-right mt-hide_all_fields"><?php echo esc_textarea($instance['after_link']); ?></textarea> |
|
| 375 | 375 | </p> |
| 376 | 376 | |
| 377 | 377 | <?php |
@@ -381,14 +381,14 @@ discard block |
||
| 381 | 381 | * @param GravityView_Recent_Entries_Widget $this WP_Widget object |
| 382 | 382 | * @param array $instance Current widget instance |
| 383 | 383 | */ |
| 384 | - do_action( 'gravityview_recent_entries_widget_form' , $this, $instance ); |
|
| 384 | + do_action('gravityview_recent_entries_widget_form', $this, $instance); |
|
| 385 | 385 | |
| 386 | 386 | ?> |
| 387 | 387 | |
| 388 | 388 | <script> |
| 389 | 389 | // When the widget is saved or added, refresh the Merge Tags (here for backward compatibility) |
| 390 | 390 | // WordPress 3.9 added widget-added and widget-updated actions |
| 391 | - jQuery('#<?php echo $this->get_field_id( 'view_id' ); ?>').trigger( 'change' ); |
|
| 391 | + jQuery('#<?php echo $this->get_field_id('view_id'); ?>').trigger( 'change' ); |
|
| 392 | 392 | </script> |
| 393 | 393 | <?php } |
| 394 | 394 | |