Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PodsForm often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PodsForm, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class PodsForm { |
||
|
|
|||
| 6 | |||
| 7 | /** |
||
| 8 | * @var PodsForm |
||
| 9 | */ |
||
| 10 | protected static $instance = null; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | static $field = null; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | static $field_group = null; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | static $field_type = null; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | static $field_types = array(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | static $loaded = array(); |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var int |
||
| 39 | */ |
||
| 40 | static $form_counter = 0; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Singleton handling for a basic pods_form() request |
||
| 44 | * |
||
| 45 | * @return \PodsForm |
||
| 46 | * |
||
| 47 | * @since 2.3.5 |
||
| 48 | */ |
||
| 49 | public static function init () { |
||
| 50 | if ( !is_object( self::$instance ) ) |
||
| 51 | self::$instance = new PodsForm(); |
||
| 52 | |||
| 53 | return self::$instance; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Master handler for all field / form methods |
||
| 58 | * |
||
| 59 | * @return \PodsForm |
||
| 60 | * |
||
| 61 | * @license http://www.gnu.org/licenses/gpl-2.0.html |
||
| 62 | * @since 2.0 |
||
| 63 | */ |
||
| 64 | private function __construct() { |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Prevent clones |
||
| 70 | * |
||
| 71 | * @since 2.3 |
||
| 72 | */ |
||
| 73 | private function __clone() { |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Output a field's label |
||
| 79 | * |
||
| 80 | * @since 2.0 |
||
| 81 | */ |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Output a field's label |
||
| 85 | * |
||
| 86 | * @param string $name Field name |
||
| 87 | * @param string $label Label text |
||
| 88 | * @param string $help Help text |
||
| 89 | * @param array $options Field options |
||
| 90 | * |
||
| 91 | * @return string Label HTML |
||
| 92 | * |
||
| 93 | * @since 2.0 |
||
| 94 | */ |
||
| 95 | public static function label( $name, $label, $help = '', $options = null ) { |
||
| 96 | if ( is_array( $label ) || is_object( $label ) ) { |
||
| 97 | $options = $label; |
||
| 98 | $label = $options[ 'label' ]; |
||
| 99 | |||
| 100 | if ( empty( $label ) ) |
||
| 101 | $label = ucwords( str_replace( '_', ' ', $name ) ); |
||
| 102 | |||
| 103 | $help = $options[ 'help' ]; |
||
| 104 | } |
||
| 105 | else |
||
| 106 | $options = self::options( null, $options ); |
||
| 107 | |||
| 108 | $label = apply_filters( 'pods_form_ui_label_text', $label, $name, $help, $options ); |
||
| 109 | $help = apply_filters( 'pods_form_ui_label_help', $help, $name, $label, $options ); |
||
| 110 | |||
| 111 | ob_start(); |
||
| 112 | |||
| 113 | $name_clean = self::clean( $name ); |
||
| 114 | $name_more_clean = self::clean( $name, true ); |
||
| 115 | |||
| 116 | $type = 'label'; |
||
| 117 | $attributes = array(); |
||
| 118 | $attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean; |
||
| 119 | $attributes[ 'for' ] = ( false === strpos( $name_clean, 'pods-form-ui-' ) ? 'pods-form-ui-' : '' ) . $name_clean; |
||
| 120 | $attributes = self::merge_attributes( $attributes, $name, $type, $options, false ); |
||
| 121 | |||
| 122 | pods_view( PODS_DIR . 'ui/fields/_label.php', compact( array_keys( get_defined_vars() ) ) ); |
||
| 123 | |||
| 124 | $output = ob_get_clean(); |
||
| 125 | |||
| 126 | return apply_filters( 'pods_form_ui_' . $type, $output, $name, $label, $help, $attributes, $options ); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Output a Field Comment Paragraph |
||
| 131 | * |
||
| 132 | * @param string $name Field name |
||
| 133 | * @param string $message Field comments |
||
| 134 | * @param array $options Field options |
||
| 135 | * |
||
| 136 | * @return string Comment HTML |
||
| 137 | * |
||
| 138 | * @since 2.0 |
||
| 139 | */ |
||
| 140 | public static function comment( $name, $message = null, $options = null ) { |
||
| 141 | $options = self::options( null, $options ); |
||
| 142 | |||
| 143 | $name_more_clean = self::clean( $name, true ); |
||
| 144 | |||
| 145 | if ( isset( $options[ 'description' ] ) && !empty( $options[ 'description' ] ) ) |
||
| 146 | $message = $options[ 'description' ]; |
||
| 147 | elseif ( empty( $message ) ) |
||
| 148 | return ''; |
||
| 149 | |||
| 150 | $message = apply_filters( 'pods_form_ui_comment_text', $message, $name, $options ); |
||
| 151 | |||
| 152 | ob_start(); |
||
| 153 | |||
| 154 | $type = 'comment'; |
||
| 155 | $attributes = array(); |
||
| 156 | $attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean; |
||
| 157 | $attributes = self::merge_attributes( $attributes, $name, $type, $options, false ); |
||
| 158 | |||
| 159 | pods_view( PODS_DIR . 'ui/fields/_comment.php', compact( array_keys( get_defined_vars() ) ) ); |
||
| 160 | |||
| 161 | $output = ob_get_clean(); |
||
| 162 | |||
| 163 | return apply_filters( 'pods_form_ui_' . $type, $output, $name, $message, $attributes, $options ); |
||
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Output a field |
||
| 168 | * |
||
| 169 | * @param string $name Field name |
||
| 170 | * @param mixed $value Field value |
||
| 171 | * @param string $type Field type |
||
| 172 | * @param array $options Field options |
||
| 173 | * @param array $pod Pod data |
||
| 174 | * @param int $id Item ID |
||
| 175 | * |
||
| 176 | * @return string Field HTML |
||
| 177 | * |
||
| 178 | * @since 2.0 |
||
| 179 | */ |
||
| 180 | public static function field( $name, $value, $type = 'text', $options = null, $pod = null, $id = null ) { |
||
| 181 | // Take a field array |
||
| 182 | if ( is_array( $name ) || is_object( $name ) ) { |
||
| 183 | $options = $name; |
||
| 184 | |||
| 185 | if ( is_object( $type ) ) { |
||
| 186 | $pod = $type; |
||
| 187 | $id = $options; |
||
| 188 | } |
||
| 189 | |||
| 190 | $name = pods_v( 'name', $options ); |
||
| 191 | $type = pods_v( 'type', $options ); |
||
| 192 | } |
||
| 193 | |||
| 194 | $options = self::options( $type, $options ); |
||
| 195 | |||
| 196 | if ( null === $value || ( '' === $value && 'boolean' == $type ) || ( !empty( $pod ) && empty( $id ) ) ) |
||
| 197 | $value = self::default_value( $value, $type, $name, $options, $pod, $id ); |
||
| 198 | |||
| 199 | if ( false === self::permission( $type, $name, $options, null, $pod, $id ) ) |
||
| 200 | return false; |
||
| 201 | |||
| 202 | $value = apply_filters( 'pods_form_ui_field_' . $type . '_value', $value, $name, $options, $pod, $id ); |
||
| 203 | $form_field_type = self::$field_type; |
||
| 204 | |||
| 205 | ob_start(); |
||
| 206 | |||
| 207 | $helper = false; |
||
| 208 | |||
| 209 | if ( 0 < strlen( pods_v( 'input_helper', $options ) ) ) |
||
| 210 | $helper = pods_api()->load_helper( array( 'name' => $options[ 'input_helper' ] ) ); |
||
| 211 | |||
| 212 | if ( ( !isset( $options[ 'data' ] ) || empty( $options[ 'data' ] ) ) && is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'data' ) ) |
||
| 213 | $data = $options[ 'data' ] = self::$loaded[ $type ]->data( $name, $value, $options, $pod, $id, true ); |
||
| 214 | |||
| 215 | if ( true === apply_filters( 'pods_form_ui_field_' . $type . '_override', false, $name, $value, $options, $pod, $id ) ) |
||
| 216 | do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id ); |
||
| 217 | elseif ( !empty( $helper ) && 0 < strlen( pods_v( 'code', $helper ) ) && false === strpos( $helper[ 'code' ], '$this->' ) && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) ) |
||
| 218 | eval( '?>' . $helper[ 'code' ] ); |
||
| 219 | elseif ( method_exists( get_class(), 'field_' . $type ) ) |
||
| 220 | echo call_user_func( array( get_class(), 'field_' . $type ), $name, $value, $options ); |
||
| 221 | elseif ( is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'input' ) ) |
||
| 222 | self::$loaded[ $type ]->input( $name, $value, $options, $pod, $id ); |
||
| 223 | else |
||
| 224 | do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id ); |
||
| 225 | |||
| 226 | $output = ob_get_clean(); |
||
| 227 | |||
| 228 | return apply_filters( 'pods_form_ui_field_' . $type, $output, $name, $value, $options, $pod, $id ); |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Output field type 'db' |
||
| 233 | * |
||
| 234 | * Used for field names and other places where only [a-z0-9_] is accepted |
||
| 235 | * |
||
| 236 | * @since 2.0 |
||
| 237 | */ |
||
| 238 | View Code Duplication | protected static function field_db( $name, $value = null, $options = null ) { |
|
| 239 | $form_field_type = self::$field_type; |
||
| 240 | |||
| 241 | ob_start(); |
||
| 242 | |||
| 243 | pods_view( PODS_DIR . 'ui/fields/_db.php', compact( array_keys( get_defined_vars() ) ) ); |
||
| 244 | |||
| 245 | $output = ob_get_clean(); |
||
| 246 | |||
| 247 | return apply_filters( 'pods_form_ui_field_db', $output, $name, $value, $options ); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Output a hidden field |
||
| 252 | */ |
||
| 253 | View Code Duplication | protected static function field_hidden( $name, $value = null, $options = null ) { |
|
| 254 | $form_field_type = self::$field_type; |
||
| 255 | |||
| 256 | ob_start(); |
||
| 257 | |||
| 258 | pods_view( PODS_DIR . 'ui/fields/_hidden.php', compact( array_keys( get_defined_vars() ) ) ); |
||
| 259 | |||
| 260 | $output = ob_get_clean(); |
||
| 261 | |||
| 262 | return apply_filters( 'pods_form_ui_field_hidden', $output, $name, $value, $options ); |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Returns a submit button, with provided text and appropriate class, copied from WP Core for use on the frontend |
||
| 267 | * |
||
| 268 | * @see get_submit_button |
||
| 269 | * |
||
| 270 | * @param string $text The text of the button (defaults to 'Save Changes') |
||
| 271 | * @param string $type The type of button. One of: primary, secondary, delete |
||
| 272 | * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute |
||
| 273 | * is given in $other_attributes below, $name will be used as the button's id. |
||
| 274 | * @param bool $wrap True if the output button should be wrapped in a paragraph tag, |
||
| 275 | * false otherwise. Defaults to true |
||
| 276 | * @param array|string $other_attributes Other attributes that should be output with the button, |
||
| 277 | * mapping attributes to their values, such as array( 'tabindex' => '1' ). |
||
| 278 | * These attributes will be output as attribute="value", such as tabindex="1". |
||
| 279 | * Defaults to no other attributes. Other attributes can also be provided as a |
||
| 280 | * string such as 'tabindex="1"', though the array format is typically cleaner. |
||
| 281 | * |
||
| 282 | * @since 3.0 |
||
| 283 | */ |
||
| 284 | public static function submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) { |
||
| 285 | |||
| 286 | if ( function_exists( 'get_submit_button' ) ) { |
||
| 287 | return get_submit_button( $text, $type, $name, $wrap, $other_attributes ); |
||
| 288 | } |
||
| 289 | |||
| 290 | if ( !is_array( $type ) ) { |
||
| 291 | $type = explode( ' ', $type ); |
||
| 292 | } |
||
| 293 | |||
| 294 | $button_shorthand = array( |
||
| 295 | 'primary', |
||
| 296 | 'small', |
||
| 297 | 'large' |
||
| 298 | ); |
||
| 299 | |||
| 300 | $classes = array( |
||
| 301 | 'button' |
||
| 302 | ); |
||
| 303 | |||
| 304 | foreach ( $type as $t ) { |
||
| 305 | if ( 'secondary' === $t || 'button-secondary' === $t ) { |
||
| 306 | continue; |
||
| 307 | } |
||
| 308 | |||
| 309 | $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t; |
||
| 310 | } |
||
| 311 | |||
| 312 | $class = implode( ' ', array_unique( $classes ) ); |
||
| 313 | |||
| 314 | if ( 'delete' === $type ) { |
||
| 315 | $class = 'button-secondary delete'; |
||
| 316 | } |
||
| 317 | |||
| 318 | $text = $text ? $text : __( 'Save Changes' ); |
||
| 319 | |||
| 320 | // Default the id attribute to $name unless an id was specifically provided in $other_attributes |
||
| 321 | $id = $name; |
||
| 322 | |||
| 323 | if ( is_array( $other_attributes ) && isset( $other_attributes[ 'id' ] ) ) { |
||
| 324 | $id = $other_attributes[ 'id' ]; |
||
| 325 | unset( $other_attributes[ 'id' ] ); |
||
| 326 | } |
||
| 327 | |||
| 328 | $attributes = ''; |
||
| 329 | |||
| 330 | if ( is_array( $other_attributes ) ) { |
||
| 331 | foreach ( $other_attributes as $attribute => $value ) { |
||
| 332 | $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important |
||
| 333 | } |
||
| 334 | } |
||
| 335 | elseif ( !empty( $other_attributes ) ) { // Attributes provided as a string |
||
| 336 | $attributes = $other_attributes; |
||
| 337 | } |
||
| 338 | |||
| 339 | $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ); |
||
| 340 | $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; |
||
| 341 | |||
| 342 | if ( $wrap ) { |
||
| 343 | $button = '<p class="submit">' . $button . '</p>'; |
||
| 344 | } |
||
| 345 | |||
| 346 | return $button; |
||
| 347 | |||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Output a row (label, field, and comment) |
||
| 352 | * |
||
| 353 | * @param string $name Field name |
||
| 354 | * @param mixed $value Field value |
||
| 355 | * @param string $type Field type |
||
| 356 | * @param array $options Field options |
||
| 357 | * @param array $pod Pod data |
||
| 358 | * @param int $id Item ID |
||
| 359 | * |
||
| 360 | * @return string Row HTML |
||
| 361 | * |
||
| 362 | * @since 2.0 |
||
| 363 | */ |
||
| 364 | public static function row( $name, $value, $type = 'text', $options = null, $pod = null, $id = null ) { |
||
| 365 | $options = self::options( null, $options ); |
||
| 366 | |||
| 367 | ob_start(); |
||
| 368 | |||
| 369 | pods_view( PODS_DIR . 'ui/fields/_row.php', compact( array_keys( get_defined_vars() ) ) ); |
||
| 370 | |||
| 371 | $output = ob_get_clean(); |
||
| 372 | |||
| 373 | return apply_filters( 'pods_form_ui_field_row', $output, $name, $value, $options, $pod, $id ); |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Output a field's attributes |
||
| 378 | * |
||
| 379 | * @since 2.0 |
||
| 380 | */ |
||
| 381 | public static function attributes( $attributes, $name = null, $type = null, $options = null ) { |
||
| 382 | $attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_attributes', $attributes, $name, $options ); |
||
| 383 | |||
| 384 | foreach ( $attributes as $attribute => $value ) { |
||
| 385 | if ( null === $value ) |
||
| 386 | continue; |
||
| 387 | |||
| 388 | echo ' ' . esc_attr( (string) $attribute ) . '="' . esc_attr( (string) $value ) . '"'; |
||
| 389 | } |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Output a field's data (for use with jQuery) |
||
| 394 | * |
||
| 395 | * @since 2.0 |
||
| 396 | */ |
||
| 397 | public static function data( $data, $name = null, $type = null, $options = null ) { |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Merge attributes and handle classes |
||
| 415 | * |
||
| 416 | * @since 2.0 |
||
| 417 | */ |
||
| 418 | public static function merge_attributes( $attributes, $name = null, $type = null, $options = null, $classes = '' ) { |
||
| 419 | $options = (array) $options; |
||
| 420 | |||
| 421 | if ( !in_array( $type, array( 'label', 'comment' ) ) ) { |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Setup options for a field and store them for later use |
||
| 487 | * |
||
| 488 | * @param $type |
||
| 489 | * @param $options |
||
| 490 | * |
||
| 491 | * @return array |
||
| 492 | * |
||
| 493 | * @static |
||
| 494 | * |
||
| 495 | * @since 2.0 |
||
| 496 | */ |
||
| 497 | public static function options( $type, $options ) { |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Get options for a field type and setup defaults |
||
| 547 | * |
||
| 548 | * @static |
||
| 549 | * |
||
| 550 | * @param $type |
||
| 551 | * |
||
| 552 | * @return array|null |
||
| 553 | * |
||
| 554 | * @since 2.0 |
||
| 555 | */ |
||
| 556 | public static function options_setup( $type = null, $options = null ) { |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Get Admin options for a field type and setup defaults |
||
| 605 | * |
||
| 606 | * @static |
||
| 607 | * |
||
| 608 | * @param $type |
||
| 609 | * |
||
| 610 | * @return array|null |
||
| 611 | * |
||
| 612 | * @since 2.0 |
||
| 613 | */ |
||
| 614 | public static function ui_options( $type ) { |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Get options for a field and setup defaults |
||
| 653 | * |
||
| 654 | * |
||
| 655 | * @param null $fields |
||
| 656 | * @param null $core_defaults |
||
| 657 | * @param bool $single |
||
| 658 | * |
||
| 659 | * @return array|null |
||
| 660 | * |
||
| 661 | * @static |
||
| 662 | * @since 2.0 |
||
| 663 | */ |
||
| 664 | public static function fields_setup( $fields = null, $core_defaults = null, $single = false ) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Get options for a field and setup defaults |
||
| 704 | * |
||
| 705 | * @static |
||
| 706 | * |
||
| 707 | * @param null $field |
||
| 708 | * @param null $core_defaults |
||
| 709 | * @param null $type |
||
| 710 | * |
||
| 711 | * @return array|null |
||
| 712 | * |
||
| 713 | * @since 2.0 |
||
| 714 | */ |
||
| 715 | public static function field_setup( $field = null, $core_defaults = null, $type = null ) { |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Setup dependency / exclusion classes |
||
| 775 | * |
||
| 776 | * @param array $options array( 'depends-on' => ..., 'excludes-on' => ...) |
||
| 777 | * @param string $prefix |
||
| 778 | * |
||
| 779 | * @return string |
||
| 780 | * @static |
||
| 781 | * @since 2.0 |
||
| 782 | */ |
||
| 783 | public static function dependencies( $options, $prefix = '' ) { |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Change the value of the field |
||
| 831 | * |
||
| 832 | * @param mixed $value |
||
| 833 | * @param string $name |
||
| 834 | * @param array $options |
||
| 835 | * @param array $fields |
||
| 836 | * @param array $pod |
||
| 837 | * @param int $id |
||
| 838 | * @param array $traverse |
||
| 839 | * |
||
| 840 | * @since 2.3 |
||
| 841 | */ |
||
| 842 | public static function value( $type, $value = null, $name = null, $options = null, $pod = null, $id = null, $traverse = null ) { |
||
| 870 | |||
| 871 | /** |
||
| 872 | * Change the way the value of the field is displayed with Pods::get |
||
| 873 | * |
||
| 874 | * @param mixed $value |
||
| 875 | * @param string $name |
||
| 876 | * @param array $options |
||
| 877 | * @param array $fields |
||
| 878 | * @param array $pod |
||
| 879 | * @param int $id |
||
| 880 | * @param array $traverse |
||
| 881 | * |
||
| 882 | * @since 2.0 |
||
| 883 | */ |
||
| 884 | public static function display( $type, $value = null, $name = null, $options = null, $pod = null, $id = null, $traverse = null ) { |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Setup regex for JS / PHP |
||
| 906 | * |
||
| 907 | * @static |
||
| 908 | * |
||
| 909 | * @param $type |
||
| 910 | * @param $options |
||
| 911 | * |
||
| 912 | * @return mixed|void |
||
| 913 | * @since 2.0 |
||
| 914 | */ |
||
| 915 | View Code Duplication | public static function regex( $type, $options ) { |
|
| 927 | |||
| 928 | /** |
||
| 929 | * Setup value preparation for sprintf |
||
| 930 | * |
||
| 931 | * @static |
||
| 932 | * |
||
| 933 | * @param $type |
||
| 934 | * @param $options |
||
| 935 | * |
||
| 936 | * @return mixed|void |
||
| 937 | * @since 2.0 |
||
| 938 | */ |
||
| 939 | View Code Duplication | public static function prepare( $type, $options ) { |
|
| 951 | |||
| 952 | /** |
||
| 953 | * Validate a value before it's saved |
||
| 954 | * |
||
| 955 | * @param string $type |
||
| 956 | * @param mixed $value |
||
| 957 | * @param string $name |
||
| 958 | * @param array $options |
||
| 959 | * @param array $fields |
||
| 960 | * @param array $pod |
||
| 961 | * @param int $id |
||
| 962 | * @param array|object $params |
||
| 963 | * |
||
| 964 | * @static |
||
| 965 | * |
||
| 966 | * @since 2.0 |
||
| 967 | */ |
||
| 968 | public static function validate( $type, $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Change the value or perform actions after validation but before saving to the DB |
||
| 983 | * |
||
| 984 | * @param string $type |
||
| 985 | * @param mixed $value |
||
| 986 | * @param int $id |
||
| 987 | * @param string $name |
||
| 988 | * @param array $options |
||
| 989 | * @param array $fields |
||
| 990 | * @param array $pod |
||
| 991 | * @param object $params |
||
| 992 | * |
||
| 993 | * @static |
||
| 994 | * |
||
| 995 | * @since 2.0 |
||
| 996 | */ |
||
| 997 | View Code Duplication | public static function pre_save( $type, $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
|
| 1005 | |||
| 1006 | /** |
||
| 1007 | * Save the value to the DB |
||
| 1008 | * |
||
| 1009 | * @param string $type |
||
| 1010 | * @param mixed $value |
||
| 1011 | * @param int $id |
||
| 1012 | * @param string $name |
||
| 1013 | * @param array $options |
||
| 1014 | * @param array $fields |
||
| 1015 | * @param array $pod |
||
| 1016 | * @param object $params |
||
| 1017 | * |
||
| 1018 | * @static |
||
| 1019 | * |
||
| 1020 | * @since 2.3 |
||
| 1021 | */ |
||
| 1022 | View Code Duplication | public static function save( $type, $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
|
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Delete the value from the DB |
||
| 1035 | * |
||
| 1036 | * @param string $type |
||
| 1037 | * @param int $id |
||
| 1038 | * @param string $name |
||
| 1039 | * @param array $options |
||
| 1040 | * @param array $pod |
||
| 1041 | * |
||
| 1042 | * @static |
||
| 1043 | * |
||
| 1044 | * @since 2.3 |
||
| 1045 | */ |
||
| 1046 | View Code Duplication | public static function delete( $type, $id = null, $name = null, $options = null, $pod = null ) { |
|
| 1056 | |||
| 1057 | /** |
||
| 1058 | * Check if a user has permission to be editing a field |
||
| 1059 | * |
||
| 1060 | * @param $type |
||
| 1061 | * @param null $name |
||
| 1062 | * @param null $options |
||
| 1063 | * @param null $fields |
||
| 1064 | * @param null $pod |
||
| 1065 | * @param null $id |
||
| 1066 | * @param null $params |
||
| 1067 | * |
||
| 1068 | * @static |
||
| 1069 | * |
||
| 1070 | * @since 2.0 |
||
| 1071 | */ |
||
| 1072 | public static function permission( $type, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Parse the default the value |
||
| 1082 | * |
||
| 1083 | * @since 2.0 |
||
| 1084 | */ |
||
| 1085 | public static function default_value( $value, $type = 'text', $name = null, $options = null, $pod = null, $id = null ) { |
||
| 1111 | |||
| 1112 | /** |
||
| 1113 | * Clean a value for use in class / id |
||
| 1114 | * |
||
| 1115 | * @since 2.0 |
||
| 1116 | */ |
||
| 1117 | public static function clean( $input, $noarray = false, $db_field = false ) { |
||
| 1143 | |||
| 1144 | /** |
||
| 1145 | * Run admin_init methods for each field type |
||
| 1146 | * |
||
| 1147 | * @since 2.3 |
||
| 1148 | */ |
||
| 1149 | public function admin_init() { |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Autoload a Field Type's class |
||
| 1175 | * |
||
| 1176 | * @param string $field_type Field Type indentifier |
||
| 1177 | * @param string $file The Field Type class file location |
||
| 1178 | * |
||
| 1179 | * @return string |
||
| 1180 | * @access public |
||
| 1181 | * @static |
||
| 1182 | * @since 2.0 |
||
| 1183 | */ |
||
| 1184 | public static function field_loader( $field_type, $file = '' ) { |
||
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Run a method from a Field Type's class |
||
| 1241 | * |
||
| 1242 | * @param string $field_type Field Type indentifier |
||
| 1243 | * @param string $method Method name |
||
| 1244 | * @param mixed $arg More arguments |
||
| 1245 | * |
||
| 1246 | * @return mixed |
||
| 1247 | * @access public |
||
| 1248 | * @static |
||
| 1249 | * @since 2.0 |
||
| 1250 | */ |
||
| 1251 | public static function field_method() { |
||
| 1267 | |||
| 1268 | /** |
||
| 1269 | * Add a new Pod field type |
||
| 1270 | * |
||
| 1271 | * @param string $type The new field type identifier |
||
| 1272 | * @param string $file The new field type class file location |
||
| 1273 | * |
||
| 1274 | * @return array Field Type data |
||
| 1275 | * |
||
| 1276 | * @since 2.3 |
||
| 1277 | */ |
||
| 1278 | public static function register_field_type( $type, $file = null ) { |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Get a list of all available field types and include |
||
| 1299 | * |
||
| 1300 | * @return array Registered Field Types data |
||
| 1301 | * |
||
| 1302 | * @since 2.3 |
||
| 1303 | */ |
||
| 1304 | public static function field_types() { |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Get list of available tableless field types |
||
| 1367 | * |
||
| 1368 | * @return array Tableless field types |
||
| 1369 | * |
||
| 1370 | * @since 2.3 |
||
| 1371 | */ |
||
| 1372 | View Code Duplication | public static function tableless_field_types() { |
|
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Get list of available file field types |
||
| 1385 | * |
||
| 1386 | * @return array File field types |
||
| 1387 | * |
||
| 1388 | * @since 2.3 |
||
| 1389 | */ |
||
| 1390 | View Code Duplication | public static function file_field_types() { |
|
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Get list of available repeatable field types |
||
| 1403 | * |
||
| 1404 | * @return array Repeatable field types |
||
| 1405 | * |
||
| 1406 | * @since 2.3 |
||
| 1407 | */ |
||
| 1408 | public static function repeatable_field_types() { |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Get list of available number field types |
||
| 1435 | * |
||
| 1436 | * @return array Number field types |
||
| 1437 | * |
||
| 1438 | * @since 2.3 |
||
| 1439 | */ |
||
| 1440 | View Code Duplication | public static function number_field_types() { |
|
| 1450 | |||
| 1451 | /** |
||
| 1452 | * Get list of available date field types |
||
| 1453 | * |
||
| 1454 | * @return array Date field types |
||
| 1455 | * |
||
| 1456 | * @since 2.3 |
||
| 1457 | */ |
||
| 1458 | View Code Duplication | public static function date_field_types() { |
|
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Get list of available text field types |
||
| 1471 | * |
||
| 1472 | * @return array Text field types |
||
| 1473 | * |
||
| 1474 | * @since 2.3 |
||
| 1475 | */ |
||
| 1476 | public static function text_field_types() { |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Get list of available text field types |
||
| 1489 | * |
||
| 1490 | * @return array Text field types |
||
| 1491 | * |
||
| 1492 | * @since 2.3 |
||
| 1493 | */ |
||
| 1494 | public static function block_field_types() { |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Get list of available text field types |
||
| 1515 | * |
||
| 1516 | * @return array Text field types |
||
| 1517 | * |
||
| 1518 | * @since 2.3 |
||
| 1519 | */ |
||
| 1520 | public static function simple_tableless_objects() { |
||
| 1528 | |||
| 1529 | } |
||
| 1530 |