- Timestamp:
- 04/28/2020 02:28:16 PM (5 years ago)
- File:
- 1 edited
Legend:
- Unmodified
- Added
- Removed
codepress-admin-columns/trunk/classes/Helper/Strings.php
r2142970 r2293580 6 6 7 7 /** 8 * @param $url 9 * 10 * @return bool|false|string 8 11 * @since 1.3.1 9 *10 * @param $url11 *12 * @return bool|false|string13 12 */ 14 13 public function shorten_url( $url ) { … … 17 16 } 18 17 19 return ac_helper()->html->link( $url, url_shorten( $url ), array( 'title' => $url ) ); 20 } 21 22 /** 18 return ac_helper()->html->link( $url, url_shorten( $url ), [ 'title' => $url ] ); 19 } 20 21 /** 22 * @param $string 23 * 24 * @return string 23 25 * @since 1.3 24 *25 * @param $string26 *27 * @return string28 26 */ 29 27 public function strip_trim( $string ) { … … 33 31 /** 34 32 * Count the number of words in a string (multibyte-compatible) 35 * @since 3.036 33 * 37 34 * @param $string 38 35 * 39 36 * @return int Number of words 37 * @since 3.0 40 38 */ 41 39 public function word_count( $string ) { … … 50 48 } 51 49 52 $patterns = array(50 $patterns = [ 53 51 'strip' => '/<[a-zA-Z\/][^<>]*>/', 54 52 'clean' => '/[0-9.(),;:!?%#$¿\'"_+=\\/-]+/', 55 53 'w' => '/\S\s+/', 56 54 'c' => '/\S/', 57 );55 ]; 58 56 59 57 $string = preg_replace( $patterns['strip'], ' ', $string ); … … 69 67 70 68 /** 71 * @see wp_trim_words();72 * @since 3.073 *74 69 * @param string $string 75 70 * @param int $num_words … … 77 72 * 78 73 * @return false|string 74 * @see wp_trim_words(); 75 * @since 3.0 79 76 */ 80 77 public function trim_words( $string = '', $num_words = 30, $more = null ) { 81 if ( ! $string) {78 if ( $this->is_empty( $string ) ) { 82 79 return false; 83 80 } … … 144 141 /** 145 142 * Get RGB values from a hex color string 146 * @since 3.0147 143 * 148 144 * @param string $hex Valid hex color 149 145 * 150 146 * @return array 147 * @since 3.0 151 148 */ 152 149 public function hex_to_rgb( $hex ) { … … 158 155 /** 159 156 * Get contrasting hex color based on given hex color 160 * @since 3.0161 157 * 162 158 * @param string $hex Valid hex color 163 159 * 164 160 * @return string 161 * @since 3.0 165 162 */ 166 163 public function hex_get_contrast( $hex ) { … … 172 169 173 170 /** 171 * @param string $url 172 * 173 * @return bool 174 174 * @since 1.2.0 175 *176 * @param string $url177 *178 * @return bool179 175 */ 180 176 public function is_image( $url ) { … … 185 181 $ext = strtolower( pathinfo( strtok( $url, '?' ), PATHINFO_EXTENSION ) ); 186 182 187 return in_array( $ext, array( 'jpg', 'jpeg', 'gif', 'png', 'bmp' ) ); 188 } 189 190 /** 191 * @since 3.0 192 * 183 return in_array( $ext, [ 'jpg', 'jpeg', 'gif', 'png', 'bmp' ] ); 184 } 185 186 /** 193 187 * @param string $string 194 188 * 195 189 * @return array 190 * @since 3.0 196 191 */ 197 192 public function comma_separated_to_array( $string ) { 198 $array = array();193 $array = []; 199 194 if ( is_scalar( $string ) ) { 200 195 if ( strpos( $string, ',' ) !== false ) { 201 196 $array = array_filter( explode( ',', ac_helper()->string->strip_trim( str_replace( ' ', '', $string ) ) ) ); 202 197 } else { 203 $array = array( $string );198 $array = [ $string ]; 204 199 } 205 200 } else if ( is_array( $string ) ) { … … 211 206 212 207 /** 213 * @since 3.0214 *215 208 * @param string $string 216 209 * 217 210 * @return array 211 * @since 3.0 218 212 */ 219 213 public function string_to_array_integers( $string ) { 220 $integers = array();214 $integers = []; 221 215 222 216 foreach ( $this->comma_separated_to_array( $string ) as $k => $value ) { … … 230 224 231 225 /** 232 * @since 3.0233 *234 226 * @param string $hex Color Hex Code 235 227 * 236 228 * @return string 229 * @since 3.0 237 230 */ 238 231 public function get_color_block( $hex ) { … … 286 279 */ 287 280 public function is_not_empty( $value ) { 288 return $value || 0 === $value ;281 return $value || 0 === $value || '0' === $value; 289 282 } 290 283
Note: See TracChangeset for help on using the changeset viewer.