Changeset 8632
- Timestamp:
- 07/16/2014 10:33:58 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-classes.php
r8554 r8632 487 487 <div id="titlediv"> 488 488 <div id="titlewrap"> 489 <label class="screen-reader-text" id="title-prompt-text" for= "title"><?php_e( 'Field Group Title', 'buddypress') ?></label>490 <input type="text" name="group_name" id="title" value="<?php echo esc_attr( $this->name ); ?>" placeholder="<?php esc_attr_e( 'Field Group Title', 'buddypress'); ?>" />489 <label class="screen-reader-text" id="title-prompt-text" for="title"><?php esc_html_e( 'Field Group Title', 'buddypress') ?></label> 490 <input type="text" name="group_name" autocomplete="off" id="title" value="<?php echo esc_attr( $this->name ); ?>" /> 491 491 </div> 492 492 </div> … … 1456 1456 } 1457 1457 1458 /** Field Types ***************************************************************/ 1459 1458 1460 /** 1459 1461 * Datebox xprofile field type. … … 1474 1476 $this->name = _x( 'Date Selector', 'xprofile field type', 'buddypress' ); 1475 1477 1476 $this->set_format( '/^\d{4}-\d{1,2}-\d{1,2} 00:00:00$/', 'replace' ); // "Y-m-d 00:00:00" 1478 $this->set_format( '/^\d{4}-\d{1,2}-\d{1,2} 00:00:00$/', 'replace' ); // "Y-m-d 00:00:00" 1479 1477 1480 do_action( 'bp_xprofile_field_type_datebox', $this ); 1478 1481 } … … 1487 1490 */ 1488 1491 public function edit_field_html( array $raw_properties = array() ) { 1489 $user_id = bp_displayed_user_id(); 1490 1491 // user_id is a special optional parameter that we pass to{@link bp_the_profile_field_options()}.1492 1493 // user_id is a special optional parameter that we pass to 1494 // {@link bp_the_profile_field_options()}. 1492 1495 if ( isset( $raw_properties['user_id'] ) ) { 1493 1496 $user_id = (int) $raw_properties['user_id']; 1494 1497 unset( $raw_properties['user_id'] ); 1495 } 1496 1497 $day_html = $this->get_edit_field_html_elements( array_merge( 1498 array( 1499 'id' => bp_get_the_profile_field_input_name() . '_day', 1500 'name' => bp_get_the_profile_field_input_name() . '_day', 1501 ), 1502 $raw_properties 1498 } else { 1499 $user_id = bp_displayed_user_id(); 1500 } 1501 1502 $day_r = bp_parse_args( $raw_properties, array( 1503 'id' => bp_get_the_profile_field_input_name() . '_day', 1504 'name' => bp_get_the_profile_field_input_name() . '_day' 1503 1505 ) ); 1504 1506 1505 $month_html = $this->get_edit_field_html_elements( array_merge( 1506 array( 1507 'id' => bp_get_the_profile_field_input_name() . '_month', 1508 'name' => bp_get_the_profile_field_input_name() . '_month', 1509 ), 1510 $raw_properties 1507 $month_r = bp_parse_args( $raw_properties, array( 1508 'id' => bp_get_the_profile_field_input_name() . '_month', 1509 'name' => bp_get_the_profile_field_input_name() . '_month' 1511 1510 ) ); 1512 1511 1513 $year_html = $this->get_edit_field_html_elements( array_merge( 1514 array( 1515 'id' => bp_get_the_profile_field_input_name() . '_year', 1516 'name' => bp_get_the_profile_field_input_name() . '_year', 1517 ), 1518 $raw_properties 1519 ) ); 1520 ?> 1512 $year_r = bp_parse_args( $raw_properties, array( 1513 'id' => bp_get_the_profile_field_input_name() . '_year', 1514 'name' => bp_get_the_profile_field_input_name() . '_year' 1515 ) ); ?> 1516 1521 1517 <div class="datebox"> 1522 1518 … … 1524 1520 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 1525 1521 1526 <select <?php echo $day_html; ?>> 1527 <?php bp_the_profile_field_options( array( 'type' => 'day', 'user_id' => $user_id ) ); ?> 1522 <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>> 1523 <?php bp_the_profile_field_options( array( 1524 'type' => 'day', 1525 'user_id' => $user_id 1526 ) ); ?> 1528 1527 </select> 1529 1528 1530 <select <?php echo $month_html; ?>> 1531 <?php bp_the_profile_field_options( array( 'type' => 'month', 'user_id' => $user_id ) ); ?> 1529 <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>> 1530 <?php bp_the_profile_field_options( array( 1531 'type' => 'month', 1532 'user_id' => $user_id 1533 ) ); ?> 1532 1534 </select> 1533 1535 1534 <select <?php echo $year_html; ?>> 1535 <?php bp_the_profile_field_options( array( 'type' => 'year', 'user_id' => $user_id ) ); ?> 1536 <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>> 1537 <?php bp_the_profile_field_options( array( 1538 'type' => 'year', 1539 'user_id' => $user_id 1540 ) ); ?> 1536 1541 </select> 1537 1542 … … 1555 1560 */ 1556 1561 public function edit_field_options_html( array $args = array() ) { 1557 $options = $this->field_obj->get_children(); 1558 $date = BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ); 1559 1562 1563 $date = BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ); 1560 1564 $day = 0; 1561 1565 $month = 0; … … 1580 1584 } 1581 1585 1582 // Check for updated posted values, and errors preventing them from being saved first time. 1586 // Check for updated posted values, and errors preventing them from 1587 // being saved first time. 1583 1588 if ( ! empty( $_POST['field_' . $this->field_obj->id . '_day'] ) ) { 1584 1589 $new_day = (int) $_POST['field_' . $this->field_obj->id . '_day']; … … 1610 1615 1611 1616 $months = array( 1612 __( 'January', 'buddypress' ),1613 __( 'February', 'buddypress' ),1614 __( 'March', 'buddypress' ),1615 __( 'April', 'buddypress' ),1616 __( 'May', 'buddypress' ),1617 __( 'June', 'buddypress' ),1618 __( 'July', 'buddypress' ),1619 __( 'August', 'buddypress' ),1617 __( 'January', 'buddypress' ), 1618 __( 'February', 'buddypress' ), 1619 __( 'March', 'buddypress' ), 1620 __( 'April', 'buddypress' ), 1621 __( 'May', 'buddypress' ), 1622 __( 'June', 'buddypress' ), 1623 __( 'July', 'buddypress' ), 1624 __( 'August', 'buddypress' ), 1620 1625 __( 'September', 'buddypress' ), 1621 __( 'October', 'buddypress' ),1622 __( 'November', 'buddypress' ),1623 __( 'December', 'buddypress' )1626 __( 'October', 'buddypress' ), 1627 __( 'November', 'buddypress' ), 1628 __( 'December', 'buddypress' ) 1624 1629 ); 1625 1630 … … 1652 1657 */ 1653 1658 public function admin_field_html( array $raw_properties = array() ) { 1654 $day_html = $this->get_edit_field_html_elements( array_merge( 1655 array( 1656 'id' => bp_get_the_profile_field_input_name() . '_day', 1657 'name' => bp_get_the_profile_field_input_name() . '_day', 1658 ), 1659 $raw_properties 1659 1660 $day_r = bp_parse_args( $raw_properties, array( 1661 'id' => bp_get_the_profile_field_input_name() . '_day', 1662 'name' => bp_get_the_profile_field_input_name() . '_day' 1660 1663 ) ); 1661 1664 1662 $month_html = $this->get_edit_field_html_elements( array_merge( 1663 array( 1664 'id' => bp_get_the_profile_field_input_name() . '_month', 1665 'name' => bp_get_the_profile_field_input_name() . '_month', 1666 ), 1667 $raw_properties 1665 $month_r = bp_parse_args( $raw_properties, array( 1666 'id' => bp_get_the_profile_field_input_name() . '_month', 1667 'name' => bp_get_the_profile_field_input_name() . '_month' 1668 1668 ) ); 1669 1669 1670 $year_html = $this->get_edit_field_html_elements( array_merge( 1671 array( 1672 'id' => bp_get_the_profile_field_input_name() . '_year', 1673 'name' => bp_get_the_profile_field_input_name() . '_year', 1674 ), 1675 $raw_properties 1676 ) ); 1677 ?> 1678 <select <?php echo $day_html; ?>> 1679 <?php bp_the_profile_field_options( 'type=day' ); ?> 1670 $year_r = bp_parse_args( $raw_properties, array( 1671 'id' => bp_get_the_profile_field_input_name() . '_year', 1672 'name' => bp_get_the_profile_field_input_name() . '_year' 1673 ) ); ?> 1674 1675 <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>> 1676 <?php bp_the_profile_field_options( array( 'type' => 'day' ) ); ?> 1680 1677 </select> 1681 1678 1682 <select <?php echo $ month_html; ?>>1683 <?php bp_the_profile_field_options( 'type=month'); ?>1679 <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>> 1680 <?php bp_the_profile_field_options( array( 'type' => 'month' ) ); ?> 1684 1681 </select> 1685 1682 1686 <select <?php echo $ year_html; ?>>1687 <?php bp_the_profile_field_options( 'type=year'); ?>1683 <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>> 1684 <?php bp_the_profile_field_options( array( 'type' => 'year' ) ); ?> 1688 1685 </select> 1686 1689 1687 <?php 1690 1688 } … … 1710 1708 */ 1711 1709 public static function display_filter( $field_value ) { 1710 1712 1711 // If Unix timestamp 1713 if ( is_numeric( $field_value ) ) { 1714 $field_value = bp_format_time( $field_value, true, false ); 1715 1716 // If MySQL timestamp 1717 } else { 1718 $field_value = bp_format_time( strtotime( $field_value ), true, false ); 1719 } 1720 1721 return $field_value; 1712 if ( ! is_numeric( $field_value ) ) { 1713 $field_value = strtotime( $field_value ); 1714 } 1715 1716 return bp_format_time( $field_value, true, false ); 1722 1717 } 1723 1718 } … … 1758 1753 */ 1759 1754 public function edit_field_html( array $raw_properties = array() ) { 1760 $user_id = bp_displayed_user_id(); 1761 1762 // user_id is a special optional parameter that we pass to{@link bp_the_profile_field_options()}.1755 1756 // user_id is a special optional parameter that we pass to 1757 // {@link bp_the_profile_field_options()}. 1763 1758 if ( isset( $raw_properties['user_id'] ) ) { 1764 1759 $user_id = (int) $raw_properties['user_id']; 1765 1760 unset( $raw_properties['user_id'] ); 1766 } 1767 ?> 1761 } else { 1762 $user_id = bp_displayed_user_id(); 1763 } ?> 1764 1768 1765 <div class="checkbox"> 1769 1770 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 1766 <label for="<?php bp_the_profile_field_input_name(); ?>"> 1767 <?php bp_the_profile_field_name(); ?> 1768 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 1769 <?php esc_html_e( '(required)', 'buddypress' ); ?> 1770 <?php endif; ?> 1771 </label> 1772 1771 1773 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 1772 <?php bp_the_profile_field_options( "user_id={$user_id}" ); ?> 1774 1775 <?php bp_the_profile_field_options( array( 1776 'user_id' => $user_id 1777 ) ); ?> 1773 1778 1774 1779 </div> 1780 1775 1781 <?php 1776 1782 } … … 1797 1803 $html = ''; 1798 1804 1799 // Check for updated posted values, but errors preventing them from being saved first time 1805 // Check for updated posted values, but errors preventing them from 1806 // being saved first time 1800 1807 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_values != maybe_serialize( $_POST['field_' . $this->field_obj->id] ) ) { 1801 1808 if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) { … … 1810 1817 for ( $j = 0, $count_values = count( $option_values ); $j < $count_values; ++$j ) { 1811 1818 1812 // Run the allowed option name through the before_save filter, so we'll be sure to get a match 1819 // Run the allowed option name through the before_save filter, 1820 // so we'll be sure to get a match 1813 1821 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 1814 1822 … … 1819 1827 } 1820 1828 1821 // If the user has not yet supplied a value for this field, check to see whether there is a default value available 1829 // If the user has not yet supplied a value for this field, check to 1830 // see whether there is a default value available 1822 1831 if ( ! is_array( $option_values ) && empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) { 1823 1832 $selected = ' checked="checked"'; … … 1896 1905 */ 1897 1906 public function edit_field_html( array $raw_properties = array() ) { 1898 $user_id = bp_displayed_user_id(); 1899 1900 // user_id is a special optional parameter that we pass to{@link bp_the_profile_field_options()}.1907 1908 // user_id is a special optional parameter that we pass to 1909 // {@link bp_the_profile_field_options()}. 1901 1910 if ( isset( $raw_properties['user_id'] ) ) { 1902 1911 $user_id = (int) $raw_properties['user_id']; 1903 1912 unset( $raw_properties['user_id'] ); 1904 } 1905 ?> 1913 } else { 1914 $user_id = bp_displayed_user_id(); 1915 } ?> 1916 1906 1917 <div class="radio"> 1907 1918 1908 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 1919 <label for="<?php bp_the_profile_field_input_name(); ?>"> 1920 <?php bp_the_profile_field_name(); ?> 1921 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 1922 <?php esc_html_e( '(required)', 'buddypress' ); ?> 1923 <?php endif; ?> 1924 </label> 1925 1909 1926 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 1910 <?php bp_the_profile_field_options( "user_id={$user_id}" ); 1927 1928 <?php bp_the_profile_field_options( array( 'user_id' => $user_id ) ); 1911 1929 1912 1930 if ( ! bp_get_the_profile_field_is_required() ) : ?> 1913 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );"><?php esc_html_e( 'Clear', 'buddypress' ); ?></a> 1931 1932 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );"> 1933 <?php esc_html_e( 'Clear', 'buddypress' ); ?> 1934 </a> 1935 1914 1936 <?php endif; ?> 1915 1937 1916 1938 </div> 1939 1917 1940 <?php 1918 1941 } … … 1940 1963 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 1941 1964 1942 // Check for updated posted values, but errors preventing them from being saved first time 1965 // Check for updated posted values, but errors preventing them from 1966 // being saved first time 1943 1967 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_value != $_POST['field_' . $this->field_obj->id] ) { 1944 1968 if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) { … … 1947 1971 } 1948 1972 1949 // Run the allowed option name through the before_save filter, so we'll be sure to get a match 1973 // Run the allowed option name through the before_save filter, so 1974 // we'll be sure to get a match 1950 1975 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 1951 1976 $selected = ''; … … 1979 2004 bp_the_profile_field_options(); 1980 2005 1981 if ( ! bp_get_the_profile_field_is_required() ) : ?> 1982 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );"><?php esc_html_e( 'Clear', 'buddypress' ); ?></a> 1983 <?php endif; ?> 1984 <?php 2006 if ( bp_get_the_profile_field_is_required() ) { 2007 return; 2008 } ?> 2009 2010 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );"> 2011 <?php esc_html_e( 'Clear', 'buddypress' ); ?> 2012 </a> 2013 2014 <?php 1985 2015 } 1986 2016 … … 2034 2064 */ 2035 2065 public function edit_field_html( array $raw_properties = array() ) { 2036 $user_id = bp_displayed_user_id(); 2037 2038 // user_id is a special optional parameter that we pass to{@link bp_the_profile_field_options()}.2066 2067 // user_id is a special optional parameter that we pass to 2068 // {@link bp_the_profile_field_options()}. 2039 2069 if ( isset( $raw_properties['user_id'] ) ) { 2040 2070 $user_id = (int) $raw_properties['user_id']; 2041 2071 unset( $raw_properties['user_id'] ); 2042 } 2043 2044 $html = $this->get_edit_field_html_elements( array_merge( 2045 array( 2046 'multiple' => 'multiple', 2047 'id' => bp_get_the_profile_field_input_name() . '[]', 2048 'name' => bp_get_the_profile_field_input_name() . '[]', 2049 ), 2050 $raw_properties 2051 ) ); 2052 ?> 2072 } else { 2073 $user_id = bp_displayed_user_id(); 2074 } 2075 2076 $r = bp_parse_args( $raw_properties, array( 2077 'multiple' => 'multiple', 2078 'id' => bp_get_the_profile_field_input_name() . '[]', 2079 'name' => bp_get_the_profile_field_input_name() . '[]', 2080 ) ); ?> 2081 2053 2082 <label for="<?php bp_the_profile_field_input_name(); ?>[]"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 2083 2054 2084 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 2055 <select <?php echo $html; ?>> 2056 <?php bp_the_profile_field_options( "user_id={$user_id}" ); ?> 2085 2086 <select <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2087 <?php bp_the_profile_field_options( array( 2088 'user_id' => $user_id 2089 ) ); ?> 2057 2090 </select> 2058 2091 2059 2092 <?php if ( ! bp_get_the_profile_field_is_required() ) : ?> 2060 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>[]' );"><?php esc_html_e( 'Clear', 'buddypress' ); ?></a> 2093 2094 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>[]' );"> 2095 <?php esc_html_e( 'Clear', 'buddypress' ); ?> 2096 </a> 2097 2061 2098 <?php endif; ?> 2062 2099 <?php … … 2091 2128 $selected = ''; 2092 2129 2093 // Check for updated posted values, but errors preventing them from being saved first time 2130 // Check for updated posted values, but errors preventing them from 2131 // being saved first time 2094 2132 foreach( $option_values as $i => $option_value ) { 2095 2133 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id][$i] != $option_value ) { … … 2100 2138 } 2101 2139 2102 // Run the allowed option name through the before_save filter, so we'll be sure to get a match 2140 // Run the allowed option name through the before_save filter, so 2141 // we'll be sure to get a match 2103 2142 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 2104 2143 … … 2128 2167 */ 2129 2168 public function admin_field_html( array $raw_properties = array() ) { 2130 $html = $this->get_edit_field_html_elements( array_merge( 2131 array( 'multiple' => 'multiple' ), 2132 $raw_properties 2133 ) ); 2134 ?> 2135 <select <?php echo $html; ?>> 2169 $r = bp_parse_args( $raw_properties, array( 2170 'multiple' => 'multiple' 2171 ) ); ?> 2172 2173 <select <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2136 2174 <?php bp_the_profile_field_options(); ?> 2137 2175 </select> 2138 <?php 2176 2177 <?php 2139 2178 } 2140 2179 … … 2186 2225 */ 2187 2226 public function edit_field_html( array $raw_properties = array() ) { 2188 $user_id = bp_displayed_user_id(); 2189 2190 // user_id is a special optional parameter that we pass to{@link bp_the_profile_field_options()}.2227 2228 // user_id is a special optional parameter that we pass to 2229 // {@link bp_the_profile_field_options()}. 2191 2230 if ( isset( $raw_properties['user_id'] ) ) { 2192 2231 $user_id = (int) $raw_properties['user_id']; 2193 2232 unset( $raw_properties['user_id'] ); 2194 } 2195 2196 $html = $this->get_edit_field_html_elements( $raw_properties ); 2197 ?> 2198 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 2233 } else { 2234 $user_id = bp_displayed_user_id(); 2235 } ?> 2236 2237 <label for="<?php bp_the_profile_field_input_name(); ?>"> 2238 <?php bp_the_profile_field_name(); ?> 2239 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 2240 <?php esc_html_e( '(required)', 'buddypress' ); ?> 2241 <?php endif; ?> 2242 </label> 2243 2199 2244 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 2200 <select <?php echo $html; ?>> 2201 <?php bp_the_profile_field_options( "user_id={$user_id}" ); ?> 2245 2246 <select <?php echo $this->get_edit_field_html_elements( $raw_properties ); ?>> 2247 <?php bp_the_profile_field_options( array( 'user_id' => $user_id ) ); ?> 2202 2248 </select> 2203 <?php 2249 2250 <?php 2204 2251 } 2205 2252 … … 2222 2269 2223 2270 $options = $this->field_obj->get_children(); 2224 $html 2271 $html = '<option value="">' . /* translators: no option picked in select box */ esc_html__( '----', 'buddypress' ) . '</option>'; 2225 2272 2226 2273 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $this->field_obj->id] ) ) { … … 2232 2279 $selected = ''; 2233 2280 2234 // Check for updated posted values, but errors preventing them from being saved first time 2281 // Check for updated posted values, but errors preventing them from 2282 // being saved first time 2235 2283 foreach( $option_values as $i => $option_value ) { 2236 2284 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id] != $option_value ) { … … 2241 2289 } 2242 2290 2243 // Run the allowed option name through the before_save filter, so we'll be sure to get a match 2291 // Run the allowed option name through the before_save filter, so 2292 // we'll be sure to get a match 2244 2293 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 2245 2294 … … 2269 2318 */ 2270 2319 public function admin_field_html( array $raw_properties = array() ) { 2271 $html = $this->get_edit_field_html_elements( $raw_properties );2272 ?> 2273 <select <?php echo $ html; ?>>2320 ?> 2321 2322 <select <?php echo $this->get_edit_field_html_elements( $raw_properties ); ?>> 2274 2323 <?php bp_the_profile_field_options(); ?> 2275 2324 </select> 2276 <?php 2325 2326 <?php 2277 2327 } 2278 2328 … … 2323 2373 public function edit_field_html( array $raw_properties = array() ) { 2324 2374 2325 // user_id is a special optional parameter that certain other fields types pass to {@link bp_the_profile_field_options()}. 2375 // user_id is a special optional parameter that certain other fields 2376 // types pass to {@link bp_the_profile_field_options()}. 2326 2377 if ( isset( $raw_properties['user_id'] ) ) { 2327 2378 unset( $raw_properties['user_id'] ); 2328 2379 } 2329 2380 2330 $html = $this->get_edit_field_html_elements( array_merge( 2331 array( 2332 'cols' => 40, 2333 'rows' => 5, 2334 ), 2335 $raw_properties 2336 ) ); 2337 ?> 2338 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 2381 $r = bp_parse_args( $raw_properties, array( 2382 'cols' => 40, 2383 'rows' => 5, 2384 ) ); ?> 2385 2386 <label for="<?php bp_the_profile_field_input_name(); ?>"> 2387 <?php bp_the_profile_field_name(); ?> 2388 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 2389 <?php esc_html_e( '(required)', 'buddypress' ); ?> 2390 <?php endif; ?> 2391 </label> 2392 2339 2393 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 2340 <textarea <?php echo $html; ?>><?php bp_the_profile_field_edit_value(); ?></textarea> 2341 <?php 2394 2395 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2396 <?php bp_the_profile_field_edit_value(); ?> 2397 </textarea> 2398 2399 <?php 2342 2400 } 2343 2401 … … 2351 2409 */ 2352 2410 public function admin_field_html( array $raw_properties = array() ) { 2353 $html = $this->get_edit_field_html_elements( array_merge( 2354 array( 2355 'cols' => 40, 2356 'rows' => 5, 2357 ), 2358 $raw_properties 2359 ) ); 2360 ?> 2361 <textarea <?php echo $html; ?>></textarea> 2362 <?php 2411 $r = bp_parse_args( $raw_properties, array( 2412 'cols' => 40, 2413 'rows' => 5, 2414 ) ); ?> 2415 2416 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea> 2417 2418 <?php 2363 2419 } 2364 2420 … … 2406 2462 public function edit_field_html( array $raw_properties = array() ) { 2407 2463 2408 // user_id is a special optional parameter that certain other fields types pass to {@link bp_the_profile_field_options()}. 2464 // user_id is a special optional parameter that certain other fields 2465 // types pass to {@link bp_the_profile_field_options()}. 2409 2466 if ( isset( $raw_properties['user_id'] ) ) { 2410 2467 unset( $raw_properties['user_id'] ); 2411 2468 } 2412 2469 2413 $html = $this->get_edit_field_html_elements( array_merge( 2414 array( 2415 'type' => 'text', 2416 'value' => bp_get_the_profile_field_edit_value(), 2417 ), 2418 $raw_properties 2419 ) ); 2420 ?> 2421 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 2470 $r = bp_parse_args( $raw_properties, array( 2471 'type' => 'text', 2472 'value' => bp_get_the_profile_field_edit_value(), 2473 ) ); ?> 2474 2475 <label for="<?php bp_the_profile_field_input_name(); ?>"> 2476 <?php bp_the_profile_field_name(); ?> 2477 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 2478 <?php esc_html_e( '(required)', 'buddypress' ); ?> 2479 <?php endif; ?> 2480 </label> 2481 2422 2482 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 2423 <input <?php echo $html; ?>> 2424 <?php 2483 2484 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2485 2486 <?php 2425 2487 } 2426 2488 … … 2434 2496 */ 2435 2497 public function admin_field_html( array $raw_properties = array() ) { 2436 $html = $this->get_edit_field_html_elements( array_merge( 2437 array( 'type' => 'text' ), 2438 $raw_properties 2439 ) ); 2440 ?> 2441 <input <?php echo $html; ?>> 2442 <?php 2498 2499 $r = bp_parse_args( $raw_properties, array( 2500 'type' => 'text' 2501 ) ); ?> 2502 2503 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2504 2505 <?php 2443 2506 } 2444 2507 … … 2486 2549 public function edit_field_html( array $raw_properties = array() ) { 2487 2550 2488 // user_id is a special optional parameter that certain other fields types pass to {@link bp_the_profile_field_options()}. 2551 // user_id is a special optional parameter that certain other fields 2552 // types pass to {@link bp_the_profile_field_options()}. 2489 2553 if ( isset( $raw_properties['user_id'] ) ) { 2490 2554 unset( $raw_properties['user_id'] ); 2491 2555 } 2492 2556 2493 $html = $this->get_edit_field_html_elements( array_merge( 2494 array( 2495 'type' => 'number', 2496 'value' => bp_get_the_profile_field_edit_value(), 2497 ), 2498 $raw_properties 2499 ) ); 2500 ?> 2501 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 2557 $r = bp_parse_args( $raw_properties, array( 2558 'type' => 'number', 2559 'value' => bp_get_the_profile_field_edit_value() 2560 ) ); ?> 2561 2562 <label for="<?php bp_the_profile_field_input_name(); ?>"> 2563 <?php bp_the_profile_field_name(); ?> 2564 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 2565 <?php esc_html_e( '(required)', 'buddypress' ); ?> 2566 <?php endif; ?> 2567 </label> 2568 2502 2569 <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 2503 <input <?php echo $html; ?>> 2504 <?php 2570 2571 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2572 2573 <?php 2505 2574 } 2506 2575 … … 2514 2583 */ 2515 2584 public function admin_field_html( array $raw_properties = array() ) { 2516 $html = $this->get_edit_field_html_elements( array_merge( 2517 array( 'type' => 'number' ), 2518 $raw_properties 2519 ) ); 2520 ?> 2521 <input <?php echo $html; ?>> 2585 $r = bp_parse_args( $raw_properties, array( 2586 'type' => 'number' 2587 ) ); ?> 2588 2589 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2522 2590 <?php 2523 2591 } … … 2532 2600 */ 2533 2601 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 2602 } 2603 2604 /** 2605 * URL xprofile field type. 2606 * 2607 * @since BuddyPress (2.1.0) 2608 */ 2609 class BP_XProfile_Field_Type_URL extends BP_XProfile_Field_Type { 2610 2611 /** 2612 * Constructor for the URL field type 2613 * 2614 * @since BuddyPress (2.1.0) 2615 */ 2616 public function __construct() { 2617 parent::__construct(); 2618 2619 $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); 2620 $this->name = _x( 'URL', 'xprofile field type', 'buddypress' ); 2621 2622 $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' ); 2623 2624 do_action( 'bp_xprofile_field_type_url', $this ); 2625 } 2626 2627 /** 2628 * Output the edit field HTML for this field type. 2629 * 2630 * Must be used inside the {@link bp_profile_fields()} template loop. 2631 * 2632 * @param array $raw_properties Optional key/value array of 2633 * {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} 2634 * that you want to add. 2635 * @since BuddyPress (2.1.0) 2636 */ 2637 public function edit_field_html( array $raw_properties = array() ) { 2638 2639 // `user_id` is a special optional parameter that certain other 2640 // fields types pass to {@link bp_the_profile_field_options()}. 2641 if ( isset( $raw_properties['user_id'] ) ) { 2642 unset( $raw_properties['user_id'] ); 2643 } 2644 2645 $r = bp_parse_args( $raw_properties, array( 2646 'type' => 'url', 2647 'value' => esc_url( bp_get_the_profile_field_edit_value() ), 2648 ) ); ?> 2649 2650 <label for="<?php bp_the_profile_field_input_name(); ?>"> 2651 <?php bp_the_profile_field_name(); ?> 2652 <?php if ( bp_get_the_profile_field_is_required() ) : ?> 2653 <?php esc_html_e( '(required)', 'buddypress' ); ?> 2654 <?php endif; ?> 2655 </label> 2656 2657 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2658 2659 <?php 2660 } 2661 2662 /** 2663 * Output HTML for this field type on the wp-admin Profile Fields screen. 2664 * 2665 * Must be used inside the {@link bp_profile_fields()} template loop. 2666 * 2667 * @param array $raw_properties Optional key/value array of permitted 2668 * attributes that you want to add. 2669 * @since BuddyPress (2.1.0) 2670 */ 2671 public function admin_field_html( array $raw_properties = array() ) { 2672 2673 $r = bp_parse_args( $raw_properties, array( 2674 'type' => 'url' 2675 ) ); ?> 2676 2677 <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 2678 2679 <?php 2680 } 2681 2682 /** 2683 * This method usually outputs HTML for this field type's children options 2684 * on the wp-admin Profile Fields "Add Field" and "Edit Field" screens, but 2685 * for this field type, we don't want it, so it's stubbed out. 2686 * 2687 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 2688 * @param string $control_type Optional. HTML input type used to render the current field's child options. 2689 * @since BuddyPress (2.1.0) 2690 */ 2691 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 2692 2693 /** 2694 * Format Date values for display. 2695 * 2696 * @since BuddyPress (2.1.0) 2697 * 2698 * @param string $field_value The date value, as saved in the database. 2699 * Typically, this is a MySQL-formatted date string (Y-m-d H:i:s). 2700 * @return string Date formatted by bp_format_time(). 2701 */ 2702 public static function display_filter( $field_value ) { 2703 $link = strip_tags( $field_value ); 2704 $no_scheme = preg_replace( '#^https?://#', '', rtrim( $link, '/' ) ); 2705 $url_text = str_replace( $link, $no_scheme, $field_value ); 2706 $retval = '<a href="' . esc_url( $field_value ) . '" rel="nofollow">' . esc_html( $url_text ) . '</a>'; 2707 return $field_value; 2708 } 2534 2709 } 2535 2710 … … 2718 2893 2719 2894 // Handle field types with accepts_null_value set if $values is an empty array 2720 if ( ! $validated&& is_array( $values ) && empty( $values ) && $this->accepts_null_value ) {2895 if ( ( false === $validated ) && is_array( $values ) && empty( $values ) && $this->accepts_null_value ) { 2721 2896 $validated = true; 2722 2897 } 2723 2898 2724 2899 // If there's a whitelist set, also check the $value. 2725 if ( $validated && ! empty( $values ) && ! empty( $this->validation_whitelist ) ) { 2726 2900 if ( ( true === $validated ) && ! empty( $values ) && ! empty( $this->validation_whitelist ) ) { 2727 2901 foreach ( (array) $values as $value ) { 2728 2902 $validated = in_array( $value, $this->validation_whitelist, true ); … … 2806 2980 2807 2981 <?php 2982 2983 // Does option have children? 2808 2984 $options = $current_field->get_children( true ); 2809 2985 2810 // If no children options exists for this field, check in $_POST for a submitted form (e.g. on the "new field" screen). 2811 if ( ! $options ) { 2986 // If no children options exists for this field, check in $_POST 2987 // for a submitted form (e.g. on the "new field" screen). 2988 if ( empty( $options ) ) { 2812 2989 2813 2990 $options = array(); … … 2836 3013 2837 3014 // If there are still no children options set, this must be the "new field" screen, so add one new/empty option. 2838 if ( ! $options) {3015 if ( empty( $options ) ) { 2839 3016 $options[] = (object) array( 2840 3017 'id' => -1, … … 2893 3070 } 2894 3071 2895 /** 2896 * Internal protected/private helper methods past this point. 2897 */ 3072 /** Protected *************************************************************/ 2898 3073 2899 3074 /** … … 2909 3084 protected function get_edit_field_html_elements( array $properties = array() ) { 2910 3085 2911 $ properties = array_merge(array(3086 $r = bp_parse_args( $properties, array( 2912 3087 'id' => bp_get_the_profile_field_input_name(), 2913 3088 'name' => bp_get_the_profile_field_input_name(), 2914 ) , $properties);3089 ) ); 2915 3090 2916 3091 if ( bp_get_the_profile_field_is_required() ) { 2917 $ properties['aria-required'] = 'true';2918 } 2919 2920 $html 2921 $ properties = (array) apply_filters( 'bp_xprofile_field_edit_html_elements', $properties, get_class( $this ) );2922 2923 foreach ( $ propertiesas $name => $value ) {3092 $r['aria-required'] = 'true'; 3093 } 3094 3095 $html = ''; 3096 $r = (array) apply_filters( 'bp_xprofile_field_edit_html_elements', $r, get_class( $this ) ); 3097 3098 foreach ( $r as $name => $value ) { 2924 3099 $html .= sprintf( '%s="%s" ', sanitize_key( $name ), esc_attr( $value ) ); 2925 3100 }
Note: See TracChangeset
for help on using the changeset viewer.