@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * EEH_URL helper |
| 4 | 6 | * Helper class for URL-related PHP functions |
@@ -62,7 +64,7 @@ discard block |
||
| 62 | 64 | isset($results['response']['code']) && |
| 63 | 65 | $results['response']['code'] == '200'){ |
| 64 | 66 | return true; |
| 65 | - }else{ |
|
| 67 | + } else{ |
|
| 66 | 68 | return false; |
| 67 | 69 | } |
| 68 | 70 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * ------------------------------------------------------------------------ |
| 11 | 11 | */ |
| 12 | -class EEH_URL{ |
|
| 12 | +class EEH_URL { |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * _add_query_arg |
@@ -20,26 +20,26 @@ discard block |
||
| 20 | 20 | * @param string $url |
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | - public static function add_query_args_and_nonce( $args = array(), $url = '' ) { |
|
| 24 | - if ( empty( $url )) { |
|
| 25 | - $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', 'event_espresso' ); |
|
| 26 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 27 | - __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', 'event_espresso' ), |
|
| 23 | + public static function add_query_args_and_nonce($args = array(), $url = '') { |
|
| 24 | + if (empty($url)) { |
|
| 25 | + $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', 'event_espresso'); |
|
| 26 | + $dev_msg = $user_msg."\n".sprintf( |
|
| 27 | + __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', 'event_espresso'), |
|
| 28 | 28 | __CLASS__ |
| 29 | 29 | ); |
| 30 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 30 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 31 | 31 | } |
| 32 | 32 | // check that an action exists |
| 33 | - if ( isset( $args['action'] ) && ! empty( $args['action'] )) { |
|
| 34 | - $args = array_merge( $args, array( $args['action'] . '_nonce' => wp_create_nonce( $args['action'] . '_nonce' ))); |
|
| 33 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 34 | + $args = array_merge($args, array($args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce'))); |
|
| 35 | 35 | } else { |
| 36 | - $args = array_merge( $args, array( 'action' => 'default', 'default_nonce' => wp_create_nonce( 'default_nonce' ))); |
|
| 36 | + $args = array_merge($args, array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce'))); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | //finally, let's always add a return address (if present) :) |
| 40 | - $args = !empty( $_REQUEST['action'] ) ? array_merge( $args, array( 'return' => $_REQUEST['action'] ) ) : $args; |
|
| 40 | + $args = ! empty($_REQUEST['action']) ? array_merge($args, array('return' => $_REQUEST['action'])) : $args; |
|
| 41 | 41 | |
| 42 | - return add_query_arg( $args, $url ); |
|
| 42 | + return add_query_arg($args, $url); |
|
| 43 | 43 | |
| 44 | 44 | } |
| 45 | 45 | |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | * @param string $url |
| 52 | 52 | * @return boolean |
| 53 | 53 | */ |
| 54 | - public static function remote_file_exists($url){ |
|
| 55 | - $results = wp_remote_request($url,array( |
|
| 54 | + public static function remote_file_exists($url) { |
|
| 55 | + $results = wp_remote_request($url, array( |
|
| 56 | 56 | 'method'=>'GET', |
| 57 | 57 | 'redirection'=>1, |
| 58 | 58 | )); |
| 59 | - if( ! $results instanceof WP_Error && |
|
| 59 | + if ( ! $results instanceof WP_Error && |
|
| 60 | 60 | isset($results['response']) && |
| 61 | 61 | isset($results['response']['code']) && |
| 62 | - $results['response']['code'] == '200'){ |
|
| 62 | + $results['response']['code'] == '200') { |
|
| 63 | 63 | return true; |
| 64 | - }else{ |
|
| 64 | + } else { |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -77,29 +77,29 @@ discard block |
||
| 77 | 77 | * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | - public static function refactor_url( $url = '', $remove_query = TRUE, $base_url_only = FALSE ) { |
|
| 80 | + public static function refactor_url($url = '', $remove_query = TRUE, $base_url_only = FALSE) { |
|
| 81 | 81 | // break apart incoming URL |
| 82 | - $url_bits = parse_url( $url ); |
|
| 82 | + $url_bits = parse_url($url); |
|
| 83 | 83 | // HTTP or HTTPS ? |
| 84 | - $scheme = isset( $url_bits[ 'scheme' ] ) ? $url_bits[ 'scheme' ] . '://' : 'http://'; |
|
| 84 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 85 | 85 | // domain |
| 86 | - $host = isset( $url_bits[ 'host' ] ) ? $url_bits[ 'host' ] : ''; |
|
| 86 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 87 | 87 | // if only the base URL is requested, then return that now |
| 88 | - if ( $base_url_only ) { |
|
| 89 | - return $scheme . $host; |
|
| 88 | + if ($base_url_only) { |
|
| 89 | + return $scheme.$host; |
|
| 90 | 90 | } |
| 91 | - $port = isset( $url_bits[ 'port' ] ) ? ':' . $url_bits[ 'port' ] : ''; |
|
| 92 | - $user = isset( $url_bits[ 'user' ] ) ? $url_bits[ 'user' ] : ''; |
|
| 93 | - $pass = isset( $url_bits[ 'pass' ] ) ? ':' . $url_bits[ 'pass' ] : ''; |
|
| 94 | - $pass = ( $user || $pass ) ? $pass . '@' : ''; |
|
| 95 | - $path = isset( $url_bits[ 'path' ] ) ? $url_bits[ 'path' ] : ''; |
|
| 91 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 92 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 93 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 94 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 95 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 96 | 96 | // if the query string is not required, then return what we have so far |
| 97 | - if ( $remove_query ) { |
|
| 98 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 97 | + if ($remove_query) { |
|
| 98 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 99 | 99 | } |
| 100 | - $query = isset( $url_bits[ 'query' ] ) ? '?' . $url_bits[ 'query' ] : ''; |
|
| 101 | - $fragment = isset( $url_bits[ 'fragment' ] ) ? '#' . $url_bits[ 'fragment' ] : ''; |
|
| 102 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 100 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 101 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 102 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -112,29 +112,29 @@ discard block |
||
| 112 | 112 | * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will simply return the query string |
| 113 | 113 | * @return string|array |
| 114 | 114 | */ |
| 115 | - public static function get_query_string( $url = '', $as_array = TRUE ) { |
|
| 115 | + public static function get_query_string($url = '', $as_array = TRUE) { |
|
| 116 | 116 | // break apart incoming URL |
| 117 | - $url_bits = parse_url( $url ); |
|
| 117 | + $url_bits = parse_url($url); |
|
| 118 | 118 | // grab query string from URL |
| 119 | - $query = isset( $url_bits[ 'query' ] ) ? $url_bits[ 'query' ] : ''; |
|
| 119 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 120 | 120 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 121 | - if ( ! $as_array ) { |
|
| 121 | + if ( ! $as_array) { |
|
| 122 | 122 | return $query; |
| 123 | 123 | } |
| 124 | 124 | // if no query string exists then just return an empty array now |
| 125 | - if ( empty( $query )) { |
|
| 125 | + if (empty($query)) { |
|
| 126 | 126 | return array(); |
| 127 | 127 | } |
| 128 | 128 | // empty array to hold results |
| 129 | 129 | $query_params = array(); |
| 130 | 130 | // now break apart the query string into separate params |
| 131 | - $query = explode( '&', $query ); |
|
| 131 | + $query = explode('&', $query); |
|
| 132 | 132 | // loop thru our query params |
| 133 | - foreach ( $query as $query_args ) { |
|
| 133 | + foreach ($query as $query_args) { |
|
| 134 | 134 | // break apart the key value pairs |
| 135 | - $query_args = explode( '=', $query_args ); |
|
| 135 | + $query_args = explode('=', $query_args); |
|
| 136 | 136 | // and add to our results array |
| 137 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 137 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 138 | 138 | } |
| 139 | 139 | return $query_params; |
| 140 | 140 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * prevent_prefetching |
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | - public static function prevent_prefetching(){ |
|
| 148 | + public static function prevent_prefetching() { |
|
| 149 | 149 | // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
| 150 | 150 | remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
| 151 | 151 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * add_nocache_headers |
| 157 | 157 | * @return void |
| 158 | 158 | */ |
| 159 | - public static function add_nocache_headers(){ |
|
| 159 | + public static function add_nocache_headers() { |
|
| 160 | 160 | // add no cache headers |
| 161 | 161 | // add_action( 'wp_head' , array( 'EED_Single_Page_Checkout', 'nocache_headers' ), 10 ); |
| 162 | 162 | // plus a little extra for nginx |
@@ -1,20 +1,20 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -class EE_Sample_Form extends EE_Form_Section_Proper{ |
|
| 3 | - function __construct(){ |
|
| 2 | +class EE_Sample_Form extends EE_Form_Section_Proper { |
|
| 3 | + function __construct() { |
|
| 4 | 4 | $this->_subsections = array( |
| 5 | 5 | 'h1'=>new EE_Form_Section_HTML('hello wordl'), |
| 6 | - 'name'=>new EE_Text_Input(array('required'=>true,'default'=>'your name here')), |
|
| 6 | + 'name'=>new EE_Text_Input(array('required'=>true, 'default'=>'your name here')), |
|
| 7 | 7 | 'email'=>new EE_Email_Input(array('required'=>false)), |
| 8 | - 'shirt_size'=>new EE_Select_Input(array(''=>'Please select...', 's'=> __("Small", "event_espresso"),'m'=> __("Medium", "event_espresso"),'l'=> __("Large", "event_espresso")),array('required'=>true,'default'=>'s')), |
|
| 8 | + 'shirt_size'=>new EE_Select_Input(array(''=>'Please select...', 's'=> __("Small", "event_espresso"), 'm'=> __("Medium", "event_espresso"), 'l'=> __("Large", "event_espresso")), array('required'=>true, 'default'=>'s')), |
|
| 9 | 9 | 'month_normal'=>new EE_Month_Input(), |
| 10 | 10 | 'month_leading_zero'=>new EE_Month_Input(true), |
| 11 | 11 | 'year_2'=>new EE_Year_Input(false, 1, 1), |
| 12 | - 'year_4'=>new EE_Year_Input(true, 0,10,array('default'=>'2017')), |
|
| 12 | + 'year_4'=>new EE_Year_Input(true, 0, 10, array('default'=>'2017')), |
|
| 13 | 13 | 'yes_no'=>new EE_Yes_No_Input(array('html_label_text'=> __("Yes or No", "event_espresso"))), |
| 14 | 14 | 'credit_card'=>new EE_Credit_Card_Input(), |
| 15 | 15 | 'image_1'=>new EE_Admin_File_Uploader_Input(), |
| 16 | 16 | 'image_2'=>new EE_Admin_File_Uploader_Input(), |
| 17 | - 'skillz'=>new EE_Checkbox_Multi_Input(array('php'=>'PHP','mysql'=>'MYSQL'),array('default'=>array('php'))), |
|
| 17 | + 'skillz'=>new EE_Checkbox_Multi_Input(array('php'=>'PHP', 'mysql'=>'MYSQL'), array('default'=>array('php'))), |
|
| 18 | 18 | 'float'=>new EE_Float_Input(), |
| 19 | 19 | 'essay'=>new EE_Text_Area_Input(), |
| 20 | 20 | 'amenities'=>new EE_Select_Multiple_Input( |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | * Extra validation for the 'name' input. |
| 41 | 41 | * @param EE_Text_Input $form_input |
| 42 | 42 | */ |
| 43 | - function _validate_name($form_input){ |
|
| 44 | - if($form_input->raw_value() != 'Mike'){ |
|
| 43 | + function _validate_name($form_input) { |
|
| 44 | + if ($form_input->raw_value() != 'Mike') { |
|
| 45 | 45 | $form_input->add_validation_error(__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike'); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - function _validate(){ |
|
| 49 | + function _validate() { |
|
| 50 | 50 | parent::_validate(); |
| 51 | - if($this->_subsections['shirt_size']->normalized_value() =='s' |
|
| 52 | - && $this->_subsections['year_4']->normalized_value() < 2010){ |
|
| 51 | + if ($this->_subsections['shirt_size']->normalized_value() == 's' |
|
| 52 | + && $this->_subsections['year_4']->normalized_value() < 2010) { |
|
| 53 | 53 | $this->add_validation_error(__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old'); |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -1,7 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * Event Espresso |
@@ -175,7 +176,7 @@ discard block |
||
| 175 | 176 | if( ! $this->_html_id ){ |
| 176 | 177 | if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper ){ |
| 177 | 178 | $this->_html_id = $this->_parent_section->html_id() . '-' . $this->_prep_name_for_html_id( $this->name() ); |
| 178 | - }else{ |
|
| 179 | + } else{ |
|
| 179 | 180 | $this->_html_id = $this->_prep_name_for_html_id( $this->name() ); |
| 180 | 181 | } |
| 181 | 182 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | * @type $name string the name for this form section, if you want to explicitly define it |
| 96 | 96 | * } |
| 97 | 97 | */ |
| 98 | - function __construct( $options_array = array() ) { |
|
| 98 | + function __construct($options_array = array()) { |
|
| 99 | 99 | // used by display strategies |
| 100 | 100 | EE_Registry::instance()->load_helper('HTML'); |
| 101 | 101 | // assign incoming values to properties |
| 102 | - foreach( $options_array as $key => $value ) { |
|
| 103 | - $key = '_' . $key; |
|
| 104 | - if ( property_exists( $this, $key ) && empty( $this->$key )) { |
|
| 102 | + foreach ($options_array as $key => $value) { |
|
| 103 | + $key = '_'.$key; |
|
| 104 | + if (property_exists($this, $key) && empty($this->$key)) { |
|
| 105 | 105 | $this->$key = $value; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param $parent_form_section |
| 114 | 114 | * @param $name |
| 115 | 115 | */ |
| 116 | - protected function _construct_finalize( $parent_form_section, $name ){ |
|
| 116 | + protected function _construct_finalize($parent_form_section, $name) { |
|
| 117 | 117 | $this->_construction_finalized = TRUE; |
| 118 | 118 | $this->_parent_section = $parent_form_section; |
| 119 | 119 | $this->_name = $name; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @param string $action |
| 136 | 136 | */ |
| 137 | - public function set_action( $action ) { |
|
| 137 | + public function set_action($action) { |
|
| 138 | 138 | $this->_action = $action; |
| 139 | 139 | } |
| 140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | 146 | public function method() { |
| 147 | - return ! empty( $this->_method ) ? $this->_method : 'POST'; |
|
| 147 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | /** |
| 153 | 153 | * @param string $method |
| 154 | 154 | */ |
| 155 | - public function set_method( $method ) { |
|
| 156 | - switch ( $method ) { |
|
| 155 | + public function set_method($method) { |
|
| 156 | + switch ($method) { |
|
| 157 | 157 | case 'get' : |
| 158 | 158 | case 'GET' : |
| 159 | 159 | $this->_method = 'GET'; |
@@ -171,12 +171,12 @@ discard block |
||
| 171 | 171 | * Calculation involves using the name and the parent's html id |
| 172 | 172 | * return void |
| 173 | 173 | */ |
| 174 | - protected function _set_default_html_id_if_empty(){ |
|
| 175 | - if( ! $this->_html_id ){ |
|
| 176 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper ){ |
|
| 177 | - $this->_html_id = $this->_parent_section->html_id() . '-' . $this->_prep_name_for_html_id( $this->name() ); |
|
| 178 | - }else{ |
|
| 179 | - $this->_html_id = $this->_prep_name_for_html_id( $this->name() ); |
|
| 174 | + protected function _set_default_html_id_if_empty() { |
|
| 175 | + if ( ! $this->_html_id) { |
|
| 176 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 177 | + $this->_html_id = $this->_parent_section->html_id().'-'.$this->_prep_name_for_html_id($this->name()); |
|
| 178 | + } else { |
|
| 179 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param $name |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | - private function _prep_name_for_html_id( $name ) { |
|
| 192 | - return sanitize_key( str_replace( array( ' ', ' ', '_' ), '-', $name )); |
|
| 191 | + private function _prep_name_for_html_id($name) { |
|
| 192 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | * @param bool $add_pound_sign |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - public function html_id( $add_pound_sign = FALSE ){ |
|
| 210 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
| 209 | + public function html_id($add_pound_sign = FALSE) { |
|
| 210 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | /** |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function html_class(){ |
|
| 218 | + public function html_class() { |
|
| 219 | 219 | return $this->_html_class; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | /** |
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | - public function html_style(){ |
|
| 227 | + public function html_style() { |
|
| 228 | 228 | return $this->_html_style; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | /** |
| 234 | 234 | * @param mixed $html_class |
| 235 | 235 | */ |
| 236 | - public function set_html_class( $html_class ) { |
|
| 236 | + public function set_html_class($html_class) { |
|
| 237 | 237 | $this->_html_class = $html_class; |
| 238 | 238 | } |
| 239 | 239 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | /** |
| 243 | 243 | * @param mixed $html_id |
| 244 | 244 | */ |
| 245 | - public function set_html_id( $html_id ) { |
|
| 245 | + public function set_html_id($html_id) { |
|
| 246 | 246 | $this->_html_id = $html_id; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | /** |
| 252 | 252 | * @param mixed $html_style |
| 253 | 253 | */ |
| 254 | - public function set_html_style( $html_style ) { |
|
| 254 | + public function set_html_style($html_style) { |
|
| 255 | 255 | $this->_html_style = $html_style; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | /** |
| 261 | 261 | * @param string $other_html_attributes |
| 262 | 262 | */ |
| 263 | - public function set_other_html_attributes( $other_html_attributes ) { |
|
| 263 | + public function set_other_html_attributes($other_html_attributes) { |
|
| 264 | 264 | $this->_other_html_attributes = $other_html_attributes; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | * @throws EE_Error |
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | - function name(){ |
|
| 284 | - if( ! $this->_construction_finalized ){ |
|
| 285 | - throw new EE_Error(sprintf( __( 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso' ), get_class($this) ) ); |
|
| 283 | + function name() { |
|
| 284 | + if ( ! $this->_construction_finalized) { |
|
| 285 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso'), get_class($this))); |
|
| 286 | 286 | } |
| 287 | 287 | return $this->_name; |
| 288 | 288 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * Gets the parent section |
| 294 | 294 | * @return EE_Form_Section_Proper |
| 295 | 295 | */ |
| 296 | - function parent_section(){ |
|
| 296 | + function parent_section() { |
|
| 297 | 297 | return $this->_parent_section; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -306,14 +306,14 @@ discard block |
||
| 306 | 306 | * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
| 307 | 307 | * @return string |
| 308 | 308 | */ |
| 309 | - public function form_open( $action = '', $method = '', $other_attributes = '' ) { |
|
| 310 | - if ( ! empty( $action )) { |
|
| 311 | - $this->set_action( $action ); |
|
| 309 | + public function form_open($action = '', $method = '', $other_attributes = '') { |
|
| 310 | + if ( ! empty($action)) { |
|
| 311 | + $this->set_action($action); |
|
| 312 | 312 | } |
| 313 | - if ( ! empty( $method )) { |
|
| 314 | - $this->set_method( $method ); |
|
| 313 | + if ( ! empty($method)) { |
|
| 314 | + $this->set_method($method); |
|
| 315 | 315 | } |
| 316 | - return EEH_HTML::nl( 1, 'form' ) . '<form id="' . $this->html_id() . '" action="' . $this->action() . '" method="' . $this->method() . '"' . $other_attributes . '>'; |
|
| 316 | + return EEH_HTML::nl(1, 'form').'<form id="'.$this->html_id().'" action="'.$this->action().'" method="'.$this->method().'"'.$other_attributes.'>'; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * @return string |
| 324 | 324 | */ |
| 325 | 325 | public function form_close() { |
| 326 | - return EEH_HTML::nl( -1, 'form' ) . '</form>' . EEH_HTML::nl() . '<!-- end of ee-' . $this->html_id() . '-form -->' . EEH_HTML::nl(); |
|
| 326 | + return EEH_HTML::nl( -1, 'form' ).'</form>'.EEH_HTML::nl().'<!-- end of ee-'.$this->html_id().'-form -->'.EEH_HTML::nl(); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | |
@@ -2,16 +2,16 @@ |
||
| 2 | 2 | if (!defined('EVENT_ESPRESSO_VERSION')) |
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | 4 | /** |
| 5 | - * EE_Form_Section_HTML |
|
| 6 | - * HTML to be laid out like a proper subsection |
|
| 7 | - * |
|
| 8 | - * |
|
| 9 | - * @package Event Espresso |
|
| 10 | - * @subpackage |
|
| 11 | - * @author Mike Nelson |
|
| 12 | - * |
|
| 13 | - * ------------------------------------------------------------------------ |
|
| 14 | - */ |
|
| 5 | + * EE_Form_Section_HTML |
|
| 6 | + * HTML to be laid out like a proper subsection |
|
| 7 | + * |
|
| 8 | + * |
|
| 9 | + * @package Event Espresso |
|
| 10 | + * @subpackage |
|
| 11 | + * @author Mike Nelson |
|
| 12 | + * |
|
| 13 | + * ------------------------------------------------------------------------ |
|
| 14 | + */ |
|
| 15 | 15 | class EE_Form_Section_HTML extends EE_Form_Section_Base{ |
| 16 | 16 | |
| 17 | 17 | protected $_html = ''; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | 4 | /** |
| 5 | 5 | * EE_Form_Section_HTML |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * ------------------------------------------------------------------------ |
| 14 | 14 | */ |
| 15 | -class EE_Form_Section_HTML extends EE_Form_Section_Base{ |
|
| 15 | +class EE_Form_Section_HTML extends EE_Form_Section_Base { |
|
| 16 | 16 | |
| 17 | 17 | protected $_html = ''; |
| 18 | 18 | |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | * @param string $html |
| 23 | 23 | * @param array $options_array |
| 24 | 24 | */ |
| 25 | - public function __construct( $html = '', $options_array = array() ) { |
|
| 25 | + public function __construct($html = '', $options_array = array()) { |
|
| 26 | 26 | $this->_html = $html; |
| 27 | - parent::__construct( $options_array ); |
|
| 27 | + parent::__construct($options_array); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | |
@@ -1,6 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 2 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | +} |
|
| 4 | 5 | /** |
| 5 | 6 | * EE_Form_Section_HTML |
| 6 | 7 | * HTML to be laid out like a proper subsection |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * ------------------------------------------------------------------------ |
| 27 | 27 | */ |
| 28 | -class EE_Form_Section_HTML_From_Template extends EE_Form_Section_HTML{ |
|
| 29 | - public function __construct($template_file,$args = array(), $options_array = array()) { |
|
| 28 | +class EE_Form_Section_HTML_From_Template extends EE_Form_Section_HTML { |
|
| 29 | + public function __construct($template_file, $args = array(), $options_array = array()) { |
|
| 30 | 30 | EE_Registry::instance()->load_helper('Template'); |
| 31 | - $html = EEH_Template::locate_template( $template_file, $args ); |
|
| 31 | + $html = EEH_Template::locate_template($template_file, $args); |
|
| 32 | 32 | |
| 33 | 33 | // echo " filepath:$template_file html $html"; |
| 34 | 34 | parent::__construct($html, $options_array); |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * Event Espresso |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * ------------------------------------------------------------------------ |
| 36 | 36 | */ |
| 37 | -abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base{ |
|
| 37 | +abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base { |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Array of validation errors in this section. Does not contain validation errors in subsections, however. |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * called get_validation_errors_accumulated |
| 50 | 50 | * @return EE_Validation_Error[] |
| 51 | 51 | */ |
| 52 | - public function get_validation_errors(){ |
|
| 52 | + public function get_validation_errors() { |
|
| 53 | 53 | return $this->_validation_errors; |
| 54 | 54 | } |
| 55 | 55 | /** |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | * If we want this to be customizable, we may decide to create a strategy for displaying it. |
| 58 | 58 | * @return string |
| 59 | 59 | */ |
| 60 | - public function get_validation_error_string(){ |
|
| 60 | + public function get_validation_error_string() { |
|
| 61 | 61 | $validation_error_messages = array(); |
| 62 | - if($this->get_validation_errors()){ |
|
| 63 | - foreach($this->get_validation_errors() as $validation_error){ |
|
| 64 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
| 65 | - $validation_error_messages[] =$validation_error->getMessage(); |
|
| 62 | + if ($this->get_validation_errors()) { |
|
| 63 | + foreach ($this->get_validation_errors() as $validation_error) { |
|
| 64 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 65 | + $validation_error_messages[] = $validation_error->getMessage(); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | - return implode(", ",$validation_error_messages); |
|
| 69 | + return implode(", ", $validation_error_messages); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | * @return boolean |
| 83 | 83 | */ |
| 84 | 84 | public function is_valid() { |
| 85 | - if(count($this->_validation_errors)){ |
|
| 85 | + if (count($this->_validation_errors)) { |
|
| 86 | 86 | return false; |
| 87 | - }else{ |
|
| 87 | + } else { |
|
| 88 | 88 | return true; |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | * @param Exception $previous_exception if there was an exception that caused the error, that exception |
| 110 | 110 | * @return void |
| 111 | 111 | */ |
| 112 | - function add_validation_error( $message_or_object, $error_code = NULL, $previous_exception = NULL ){ |
|
| 113 | - if($message_or_object instanceof EE_Validation_Error){ |
|
| 114 | - $validation_error= $message_or_object; |
|
| 112 | + function add_validation_error($message_or_object, $error_code = NULL, $previous_exception = NULL) { |
|
| 113 | + if ($message_or_object instanceof EE_Validation_Error) { |
|
| 114 | + $validation_error = $message_or_object; |
|
| 115 | 115 | $validation_error->set_form_section($this); |
| 116 | - }else{ |
|
| 116 | + } else { |
|
| 117 | 117 | $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
| 118 | 118 | } |
| 119 | 119 | $this->_validation_errors[] = $validation_error; |
@@ -1,6 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 2 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | +} |
|
| 4 | 5 | |
| 5 | 6 | /** |
| 6 | 7 | * Event Espresso |
@@ -84,7 +85,7 @@ discard block |
||
| 84 | 85 | public function is_valid() { |
| 85 | 86 | if(count($this->_validation_errors)){ |
| 86 | 87 | return false; |
| 87 | - }else{ |
|
| 88 | + } else{ |
|
| 88 | 89 | return true; |
| 89 | 90 | } |
| 90 | 91 | } |
@@ -113,7 +114,7 @@ discard block |
||
| 113 | 114 | if($message_or_object instanceof EE_Validation_Error){ |
| 114 | 115 | $validation_error= $message_or_object; |
| 115 | 116 | $validation_error->set_form_section($this); |
| 116 | - }else{ |
|
| 117 | + } else{ |
|
| 117 | 118 | $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
| 118 | 119 | } |
| 119 | 120 | $this->_validation_errors[] = $validation_error; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | if(isset($options_array['subsection_args'])){ |
| 48 | 48 | $subsection_args = $options_array['subsection_args']; |
| 49 | - }else{ |
|
| 49 | + } else{ |
|
| 50 | 50 | $subsection_args = array(); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | if(isset($subsection_args[$relation_name]) && |
| 102 | 102 | isset($subsection_args[$relation_name]['model_objects'])){ |
| 103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
| 104 | - }else{ |
|
| 104 | + } else{ |
|
| 105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
| 106 | 106 | } |
| 107 | 107 | $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
| 164 | 164 | if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
| 165 | 165 | $input_class = 'EE_Text_Input'; |
| 166 | - }else{ |
|
| 166 | + } else{ |
|
| 167 | 167 | //so its just one model |
| 168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
| 169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | //then we only expect there to be one |
| 256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
| 257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
| 258 | - }else{ |
|
| 258 | + } else{ |
|
| 259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
| 260 | 260 | $ids = array(); |
| 261 | 261 | foreach($related_items as $related_item){ |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
| 306 | 306 | if($model_obj){ |
| 307 | 307 | $this->_model_object = $model_obj; |
| 308 | - }else{ |
|
| 308 | + } else{ |
|
| 309 | 309 | $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -356,19 +356,19 @@ discard block |
||
| 356 | 356 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
| 357 | 357 | //there is just a foreign key on this model pointing to that one |
| 358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
| 359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
| 359 | + } elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
| 360 | 360 | //then we want to consider all of its currently-related things. |
| 361 | 361 | //if they're in this list, keep them |
| 362 | 362 | //if they're not in this list, remove them |
| 363 | 363 | //and lastly add all the new items |
| 364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
| 365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
| 365 | + } elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
| 366 | 366 | //delete everything NOT in this list |
| 367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
| 368 | 368 | if($normalized_input_value && is_array($normalized_input_value)){ |
| 369 | 369 | $where_query_params = array( |
| 370 | 370 | $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
| 371 | - }else{ |
|
| 371 | + } else{ |
|
| 372 | 372 | $where_query_params = array(); |
| 373 | 373 | } |
| 374 | 374 | $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @since 4.5.0 |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -class EE_Model_Form_Section extends EE_Form_Section_Proper{ |
|
| 14 | +class EE_Model_Form_Section extends EE_Form_Section_Proper { |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * |
@@ -36,36 +36,36 @@ discard block |
||
| 36 | 36 | * } |
| 37 | 37 | * @throws EE_Error |
| 38 | 38 | */ |
| 39 | - public function __construct($options_array = array()){ |
|
| 40 | - if(isset($options_array['model']) && $options_array['model'] instanceof EEM_Base){ |
|
| 39 | + public function __construct($options_array = array()) { |
|
| 40 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
| 41 | 41 | $this->_model = $options_array['model']; |
| 42 | 42 | } |
| 43 | - if( ! $this->_model || ! $this->_model instanceof EEM_Base ){ |
|
| 43 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
| 44 | 44 | throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", "event_espresso"))); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if(isset($options_array['subsection_args'])){ |
|
| 47 | + if (isset($options_array['subsection_args'])) { |
|
| 48 | 48 | $subsection_args = $options_array['subsection_args']; |
| 49 | - }else{ |
|
| 49 | + } else { |
|
| 50 | 50 | $subsection_args = array(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | //gather fields and relations to convert to inputs |
| 54 | 54 | //but if they're just going to exclude a field anyways, don't bother converting it to an input |
| 55 | 55 | $exclude = $this->_subsections; |
| 56 | - if(isset($options_array['exclude'])){ |
|
| 57 | - $exclude = array_merge($exclude,array_flip($options_array['exclude'])); |
|
| 56 | + if (isset($options_array['exclude'])) { |
|
| 57 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
| 58 | 58 | } |
| 59 | 59 | $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
| 60 | 60 | $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
| 61 | 61 | //convert fields and relations to inputs |
| 62 | 62 | $this->_subsections = array_merge( |
| 63 | 63 | $this->_convert_model_fields_to_inputs($model_fields), |
| 64 | - $this->_convert_model_relations_to_inputs($model_relations,$subsection_args), |
|
| 64 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
| 65 | 65 | $this->_subsections |
| 66 | 66 | ); |
| 67 | 67 | parent::__construct($options_array); |
| 68 | - if(isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class){ |
|
| 68 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
| 69 | 69 | $this->populate_model_obj($options_array['model_object']); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * } |
| 84 | 84 | * @return array |
| 85 | 85 | */ |
| 86 | - protected function _convert_model_relations_to_inputs($relations,$subsection_args = array()){ |
|
| 86 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) { |
|
| 87 | 87 | $inputs = array(); |
| 88 | - foreach( $relations as $relation_name => $relation_obj ) { |
|
| 88 | + foreach ($relations as $relation_name => $relation_obj) { |
|
| 89 | 89 | $input_constructor_args = array( |
| 90 | 90 | array_merge( |
| 91 | 91 | array( |
@@ -96,19 +96,19 @@ discard block |
||
| 96 | 96 | ) |
| 97 | 97 | ); |
| 98 | 98 | $input = NULL; |
| 99 | - switch(get_class($relation_obj)){ |
|
| 99 | + switch (get_class($relation_obj)) { |
|
| 100 | 100 | case 'EE_HABTM_Relation': |
| 101 | - if(isset($subsection_args[$relation_name]) && |
|
| 102 | - isset($subsection_args[$relation_name]['model_objects'])){ |
|
| 101 | + if (isset($subsection_args[$relation_name]) && |
|
| 102 | + isset($subsection_args[$relation_name]['model_objects'])) { |
|
| 103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
| 104 | - }else{ |
|
| 104 | + } else { |
|
| 105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
| 106 | 106 | } |
| 107 | - $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
|
| 107 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
| 108 | 108 | break; |
| 109 | 109 | default: |
| 110 | 110 | } |
| 111 | - if($input){ |
|
| 111 | + if ($input) { |
|
| 112 | 112 | $inputs[$relation_name] = $input; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -123,16 +123,16 @@ discard block |
||
| 123 | 123 | * @throws EE_Error |
| 124 | 124 | * @return EE_Form_Input_Base[] |
| 125 | 125 | */ |
| 126 | - protected function _convert_model_fields_to_inputs( $model_fields = array() ){ |
|
| 126 | + protected function _convert_model_fields_to_inputs($model_fields = array()) { |
|
| 127 | 127 | $inputs = array(); |
| 128 | - foreach( $model_fields as $field_name=>$model_field ){ |
|
| 129 | - if ( $model_field instanceof EE_Model_Field_Base ) { |
|
| 128 | + foreach ($model_fields as $field_name=>$model_field) { |
|
| 129 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
| 130 | 130 | $input_constructor_args = array(array( |
| 131 | 131 | 'required'=> ! $model_field->is_nullable() && $model_field->get_default_value() === NULL, |
| 132 | 132 | 'html_label_text'=>$model_field->get_nicename(), |
| 133 | 133 | 'default'=>$model_field->get_default_value(), |
| 134 | 134 | )); |
| 135 | - switch(get_class($model_field)){ |
|
| 135 | + switch (get_class($model_field)) { |
|
| 136 | 136 | case 'EE_All_Caps_Text_Field': |
| 137 | 137 | case 'EE_Any_Foreign_Model_Name_Field': |
| 138 | 138 | $input_class = 'EE_Text_Input'; |
@@ -141,16 +141,16 @@ discard block |
||
| 141 | 141 | $input_class = 'EE_Yes_No_Input'; |
| 142 | 142 | break; |
| 143 | 143 | case 'EE_Datetime_Field': |
| 144 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 144 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 145 | 145 | break; |
| 146 | 146 | case 'EE_Email_Field': |
| 147 | 147 | $input_class = 'EE_Email_Input'; |
| 148 | 148 | break; |
| 149 | 149 | case 'EE_Enum_Integer_Field': |
| 150 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 150 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 151 | 151 | break; |
| 152 | 152 | case 'EE_Enum_Text_Field': |
| 153 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 153 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 154 | 154 | break; |
| 155 | 155 | case 'EE_Float_Field': |
| 156 | 156 | $input_class = 'EE_Float_Input'; |
@@ -159,15 +159,15 @@ discard block |
||
| 159 | 159 | case 'EE_Foreign_Key_String_Field': |
| 160 | 160 | case 'EE_WP_User_Field': |
| 161 | 161 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
| 162 | - if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
|
| 162 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
| 163 | 163 | $input_class = 'EE_Text_Input'; |
| 164 | - }else{ |
|
| 164 | + } else { |
|
| 165 | 165 | //so its just one model |
| 166 | 166 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
| 167 | 167 | $model = EE_Registry::instance()->load_model($model_name); |
| 168 | 168 | $model_names = $model->get_all_names(array('limit'=>10)); |
| 169 | - if($model_field->is_nullable()){ |
|
| 170 | - array_unshift( $model_names, __( "Please Select", 'event_espresso' )); |
|
| 169 | + if ($model_field->is_nullable()) { |
|
| 170 | + array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
| 171 | 171 | } |
| 172 | 172 | $input_constructor_args[1] = $input_constructor_args[0]; |
| 173 | 173 | $input_constructor_args[0] = $model_names; |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $input_class = 'EE_Text_Area_Input'; |
| 179 | 179 | break; |
| 180 | 180 | case 'EE_Infinite_Integer': |
| 181 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 181 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 182 | 182 | break; |
| 183 | 183 | case 'EE_Integer_Field': |
| 184 | 184 | $input_class = 'EE_Text_Input'; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $input_class = 'EE_Text_Area_Input'; |
| 188 | 188 | break; |
| 189 | 189 | case 'EE_Money_Field': |
| 190 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 190 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 191 | 191 | break; |
| 192 | 192 | case 'EE_Post_Content_Field': |
| 193 | 193 | $input_class = 'EE_Text_Area_Input'; |
@@ -215,13 +215,13 @@ discard block |
||
| 215 | 215 | $input_class = 'EE_Yes_No_Input'; |
| 216 | 216 | break; |
| 217 | 217 | case 'EE_WP_Post_Status_Field': |
| 218 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 218 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 219 | 219 | break; |
| 220 | 220 | case 'EE_WP_Post_Type_Field': |
| 221 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 221 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 222 | 222 | break; |
| 223 | 223 | default: |
| 224 | - throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"),get_class($model_field))); |
|
| 224 | + throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"), get_class($model_field))); |
|
| 225 | 225 | } |
| 226 | 226 | $reflection = new ReflectionClass($input_class); |
| 227 | 227 | $input = $reflection->newInstanceArgs($input_constructor_args); |
@@ -239,21 +239,21 @@ discard block |
||
| 239 | 239 | * @param EE_Base_Class $model_obj |
| 240 | 240 | * @return void |
| 241 | 241 | */ |
| 242 | - public function populate_model_obj($model_obj){ |
|
| 242 | + public function populate_model_obj($model_obj) { |
|
| 243 | 243 | $model_obj = $this->_model->ensure_is_obj($model_obj); |
| 244 | 244 | $this->_model_object = $model_obj; |
| 245 | 245 | $defaults = $model_obj->model_field_array(); |
| 246 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
| 246 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
| 247 | 247 | $form_inputs = $this->inputs(); |
| 248 | - if(isset($form_inputs[$relation_name])){ |
|
| 249 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 248 | + if (isset($form_inputs[$relation_name])) { |
|
| 249 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 250 | 250 | //then we only expect there to be one |
| 251 | 251 | $related_item = $this->_model_object->get_first_related($relation_name); |
| 252 | 252 | $defaults[$relation_name] = $related_item->ID(); |
| 253 | - }else{ |
|
| 253 | + } else { |
|
| 254 | 254 | $related_items = $this->_model_object->get_many_related($relation_name); |
| 255 | 255 | $ids = array(); |
| 256 | - foreach($related_items as $related_item){ |
|
| 256 | + foreach ($related_items as $related_item) { |
|
| 257 | 257 | $ids[] = $related_item->ID(); |
| 258 | 258 | } |
| 259 | 259 | $defaults[$relation_name] = $ids; |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * values are their normalized values |
| 271 | 271 | * @return array |
| 272 | 272 | */ |
| 273 | - public function inputs_values_corresponding_to_model_fields(){ |
|
| 274 | - return array_intersect_key($this->input_values(),$this->_model->field_settings()); |
|
| 273 | + public function inputs_values_corresponding_to_model_fields() { |
|
| 274 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -294,21 +294,21 @@ discard block |
||
| 294 | 294 | public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
| 295 | 295 | parent::receive_form_submission($req_data, $validate); |
| 296 | 296 | //create or set the model object, if it isn't already |
| 297 | - if( ! $this->_model_object ){ |
|
| 297 | + if ( ! $this->_model_object) { |
|
| 298 | 298 | //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
| 299 | 299 | $pk_name = $this->_model->primary_key_name(); |
| 300 | 300 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
| 301 | - if($model_obj){ |
|
| 301 | + if ($model_obj) { |
|
| 302 | 302 | $this->_model_object = $model_obj; |
| 303 | - }else{ |
|
| 304 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
|
| 303 | + } else { |
|
| 304 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | //ok so the model object is set. Just set it with the submitted form data (don't save yet though) |
| 308 | - foreach($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value){ |
|
| 308 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value) { |
|
| 309 | 309 | //only set the non-primary key |
| 310 | - if($field_name != $this->_model->primary_key_name()){ |
|
| 311 | - $this->_model_object->set($field_name,$field_value); |
|
| 310 | + if ($field_name != $this->_model->primary_key_name()) { |
|
| 311 | + $this->_model_object->set($field_name, $field_value); |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
@@ -324,13 +324,13 @@ discard block |
||
| 324 | 324 | * @return int, 1 on a successful update, the ID of |
| 325 | 325 | * the new entry on insert; 0 on failure |
| 326 | 326 | */ |
| 327 | - public function save(){ |
|
| 328 | - if( ! $this->_model_object){ |
|
| 329 | - throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"),get_class($this->_model))); |
|
| 327 | + public function save() { |
|
| 328 | + if ( ! $this->_model_object) { |
|
| 329 | + throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"), get_class($this->_model))); |
|
| 330 | 330 | } |
| 331 | - $success = $this->_model_object->save(); |
|
| 332 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
| 333 | - if(isset($this->_subsections[$relation_name])){ |
|
| 331 | + $success = $this->_model_object->save(); |
|
| 332 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
| 333 | + if (isset($this->_subsections[$relation_name])) { |
|
| 334 | 334 | $success = $this->_save_related_info($relation_name); |
| 335 | 335 | } |
| 336 | 336 | } |
@@ -346,29 +346,29 @@ discard block |
||
| 346 | 346 | * @return bool |
| 347 | 347 | * @throws EE_Error |
| 348 | 348 | */ |
| 349 | - protected function _save_related_info($relation_name){ |
|
| 349 | + protected function _save_related_info($relation_name) { |
|
| 350 | 350 | $relation_obj = $this->_model->related_settings_for($relation_name); |
| 351 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 351 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 352 | 352 | //there is just a foreign key on this model pointing to that one |
| 353 | 353 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
| 354 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
| 354 | + }elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 355 | 355 | //then we want to consider all of its currently-related things. |
| 356 | 356 | //if they're in this list, keep them |
| 357 | 357 | //if they're not in this list, remove them |
| 358 | 358 | //and lastly add all the new items |
| 359 | 359 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
| 360 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
| 360 | + }elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
| 361 | 361 | //delete everything NOT in this list |
| 362 | 362 | $normalized_input_value = $this->get_input_value($relation_name); |
| 363 | - if($normalized_input_value && is_array($normalized_input_value)){ |
|
| 363 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
| 364 | 364 | $where_query_params = array( |
| 365 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
|
| 366 | - }else{ |
|
| 365 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value)); |
|
| 366 | + } else { |
|
| 367 | 367 | $where_query_params = array(); |
| 368 | 368 | } |
| 369 | - $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
|
| 370 | - foreach($normalized_input_value as $id){ |
|
| 371 | - $this->_model_object->_add_relation_to( $id, $relation_name ); |
|
| 369 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
| 370 | + foreach ($normalized_input_value as $id) { |
|
| 371 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | return TRUE; |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * Gets the model of this model form |
| 381 | 381 | * @return EEM_Base |
| 382 | 382 | */ |
| 383 | - public function get_model(){ |
|
| 383 | + public function get_model() { |
|
| 384 | 384 | return $this->_model; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * when receive_form_submission($req_data) was called. |
| 394 | 394 | * @return EE_Base_Class |
| 395 | 395 | */ |
| 396 | - public function get_model_object(){ |
|
| 396 | + public function get_model_object() { |
|
| 397 | 397 | return $this->_model_object; |
| 398 | 398 | } |
| 399 | 399 | |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | * gets teh default name of this form section if none is specified |
| 404 | 404 | * @return string |
| 405 | 405 | */ |
| 406 | - protected function _set_default_name_if_empty(){ |
|
| 407 | - if( ! $this->_name ){ |
|
| 408 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
| 409 | - $this->_name = $default_name; |
|
| 406 | + protected function _set_default_name_if_empty() { |
|
| 407 | + if ( ! $this->_name) { |
|
| 408 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
| 409 | + $this->_name = $default_name; |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class EE_Validation_Error extends Exception{ |
|
| 3 | +class EE_Validation_Error extends Exception { |
|
| 4 | 4 | /** |
| 5 | 5 | * Form Section from which this error originated. |
| 6 | 6 | * @var EE_Form_Section |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param EE_Form_Section_Validatable $form_section |
| 21 | 21 | * @param Exception $previous if there was an exception that caused this exception |
| 22 | 22 | */ |
| 23 | - function __construct( $message = null, $string_code = null,$form_section = null, $previous = null){ |
|
| 23 | + function __construct($message = null, $string_code = null, $form_section = null, $previous = null) { |
|
| 24 | 24 | $this->_form_section = $form_section; |
| 25 | 25 | $this->_string_code = $string_code; |
| 26 | 26 | parent::__construct($message, 500, $previous); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * returns teh form section which caused the error. |
| 31 | 31 | * @return EE_Form_Section_Validatable |
| 32 | 32 | */ |
| 33 | - public function get_form_section(){ |
|
| 33 | + public function get_form_section() { |
|
| 34 | 34 | return $this->_form_section; |
| 35 | 35 | } |
| 36 | 36 | /** |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param EE_Form_Section_Validatable $form_section |
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | - public function set_form_section($form_section){ |
|
| 41 | + public function set_form_section($form_section) { |
|
| 42 | 42 | $this->_form_section = $form_section; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -8,15 +8,15 @@ |
||
| 8 | 8 | * @since 4.6 |
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | -class EE_Admin_File_Uploader_Input extends EE_Form_Input_Base{ |
|
| 11 | +class EE_Admin_File_Uploader_Input extends EE_Form_Input_Base { |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @param array $input_settings |
| 15 | 15 | */ |
| 16 | - function __construct($input_settings = array()){ |
|
| 16 | + function __construct($input_settings = array()) { |
|
| 17 | 17 | $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy()); |
| 18 | 18 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
| 19 | - $this->_add_validation_strategy(new EE_URL_Validation_Strategy( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) ); |
|
| 19 | + $this->_add_validation_strategy(new EE_URL_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : NULL)); |
|
| 20 | 20 | parent::__construct($input_settings); |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |