[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress XProfile Classes. 4 * 5 * @package BuddyPress 6 * @subpackage XProfileClasses 7 * @since 2.1.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * URL xprofile field type. 15 * 16 * @since 2.1.0 17 */ 18 class BP_XProfile_Field_Type_URL extends BP_XProfile_Field_Type { 19 20 /** 21 * Constructor for the URL field type 22 * 23 * @since 2.1.0 24 */ 25 public function __construct() { 26 parent::__construct(); 27 28 $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); 29 $this->name = _x( 'URL', 'xprofile field type', 'buddypress' ); 30 31 $this->set_format( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', 'replace' ); 32 33 /** 34 * Fires inside __construct() method for BP_XProfile_Field_Type_URL class. 35 * 36 * @since 2.0.0 37 * 38 * @param BP_XProfile_Field_Type_URL $this Current instance of 39 * the field type URL. 40 */ 41 do_action( 'bp_xprofile_field_type_url', $this ); 42 } 43 44 /** 45 * Output the edit field HTML for this field type. 46 * 47 * Must be used inside the {@link bp_profile_fields()} template loop. 48 * 49 * @since 2.1.0 50 * 51 * @param array $raw_properties Optional key/value array of 52 * {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} 53 * that you want to add. 54 */ 55 public function edit_field_html( array $raw_properties = array() ) { 56 57 // `user_id` is a special optional parameter that certain other 58 // fields types pass to {@link bp_the_profile_field_options()}. 59 if ( isset( $raw_properties['user_id'] ) ) { 60 unset( $raw_properties['user_id'] ); 61 } 62 63 $r = bp_parse_args( $raw_properties, array( 64 'type' => 'text', 65 'inputmode' => 'url', 66 'value' => esc_url( bp_get_the_profile_field_edit_value() ), 67 ) ); ?> 68 69 <legend id="<?php bp_the_profile_field_input_name(); ?>-1"> 70 <?php bp_the_profile_field_name(); ?> 71 <?php bp_the_profile_field_required_label(); ?> 72 </legend> 73 74 <?php 75 76 /** This action is documented in bp-xprofile/bp-xprofile-classes */ 77 do_action( bp_get_the_profile_field_errors_action() ); ?> 78 79 <input <?php echo $this->get_edit_field_html_elements( $r ); ?> aria-labelledby="<?php bp_the_profile_field_input_name(); ?>-1" aria-describedby="<?php bp_the_profile_field_input_name(); ?>-3"> 80 81 <?php if ( bp_get_the_profile_field_description() ) : ?> 82 <p class="description" id="<?php bp_the_profile_field_input_name(); ?>-3"><?php bp_the_profile_field_description(); ?></p> 83 <?php endif; ?> 84 85 <?php 86 } 87 88 /** 89 * Output HTML for this field type on the wp-admin Profile Fields screen. 90 * 91 * Must be used inside the {@link bp_profile_fields()} template loop. 92 * 93 * @since 2.1.0 94 * 95 * @param array $raw_properties Optional key/value array of permitted 96 * attributes that you want to add. 97 */ 98 public function admin_field_html( array $raw_properties = array() ) { 99 100 $r = bp_parse_args( $raw_properties, array( 101 'type' => 'url' 102 ) ); ?> 103 104 <label for="<?php bp_the_profile_field_input_name(); ?>" class="screen-reader-text"><?php 105 /* translators: accessibility text */ 106 esc_html_e( 'URL', 'buddypress' ); 107 ?></label> 108 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 109 110 <?php 111 } 112 113 /** 114 * This method usually outputs HTML for this field type's children options 115 * on the wp-admin Profile Fields "Add Field" and "Edit Field" screens, but 116 * for this field type, we don't want it, so it's stubbed out. 117 * 118 * @since 2.1.0 119 * 120 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 121 * @param string $control_type Optional. HTML input type used to render the current 122 * field's child options. 123 */ 124 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 125 126 /** 127 * Modify submitted URL values before validation. 128 * 129 * The URL validation regex requires a http(s) protocol, so that all 130 * values saved in the database are fully-formed URLs. However, we 131 * still want to allow users to enter URLs without a protocol, for a 132 * better user experience. So we catch submitted URL values, and if 133 * the protocol is missing, we prepend 'http://' before passing to 134 * is_valid(). 135 * 136 * @since 2.1.0 137 * @since 2.4.0 Added the `$field_id` parameter. 138 * 139 * @param string $submitted_value Raw value submitted by the user. 140 * @param string|int $field_id Optional. ID of the field. 141 * @return string 142 */ 143 public static function pre_validate_filter( $submitted_value = '', $field_id = '' ) { 144 145 // Allow empty URL values. 146 if ( empty( $submitted_value ) ) { 147 return ''; 148 } 149 150 // Run some checks on the submitted value. 151 if ( false === strpos( $submitted_value, ':' ) && 152 substr( $submitted_value, 0, 1 ) !== '/' && 153 substr( $submitted_value, 0, 1 ) !== '#' && 154 ! preg_match( '/^[a-z0-9-]+?\.php/i', $submitted_value ) 155 ) { 156 $submitted_value = 'http://' . $submitted_value; 157 } 158 159 return $submitted_value; 160 } 161 162 /** 163 * Format URL values for display. 164 * 165 * @since 2.1.0 166 * @since 2.4.0 Added the `$field_id` parameter. 167 * 168 * @param string $field_value The URL value, as saved in the database. 169 * @param string|int $field_id Optional. ID of the field. 170 * @return string URL converted to a link. 171 */ 172 public static function display_filter( $field_value, $field_id = '' ) { 173 $link = strip_tags( $field_value ); 174 $no_scheme = preg_replace( '#^https?://#', '', rtrim( $link, '/' ) ); 175 $url_text = str_replace( $link, $no_scheme, $field_value ); 176 return '<a href="' . esc_url( $field_value ) . '" rel="nofollow">' . esc_html( $url_text ) . '</a>'; 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 9 01:01:43 2021 | Cross-referenced by PHPXref 0.7.1 |