Plugin Directory


Ignore:
Timestamp:
04/28/2020 02:28:16 PM (5 years ago)
Author:
tschutter
Message:

trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • codepress-admin-columns/trunk/classes/Helper/Strings.php

    r2142970r2293580 
    66
    77    /**
     8     * @param $url
     9     *
     10     * @return bool|false|string
    811     * @since 1.3.1
    9      *
    10      * @param $url
    11      *
    12      * @return bool|false|string
    1312     */
    1413    public function shorten_url( $url ) {
     
    1716        }
    1817
    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
    2325     * @since 1.3
    24      *
    25      * @param $string
    26      *
    27      * @return string
    2826     */
    2927    public function strip_trim( $string ) {
     
    3331    /**
    3432     * Count the number of words in a string (multibyte-compatible)
    35      * @since 3.0
    3633     *
    3734     * @param $string
    3835     *
    3936     * @return int Number of words
     37     * @since 3.0
    4038     */
    4139    public function word_count( $string ) {
     
    5048        }
    5149
    52         $patterns = array(
     50        $patterns = [
    5351            'strip' => '/<[a-zA-Z\/][^<>]*>/',
    5452            'clean' => '/[0-9.(),;:!?%#$¿\'"_+=\\/-]+/',
    5553            'w'     => '/\S\s+/',
    5654            'c'     => '/\S/',
    57         );
     55        ];
    5856
    5957        $string = preg_replace( $patterns['strip'], ' ', $string );
     
    6967
    7068    /**
    71      * @see   wp_trim_words();
    72      * @since 3.0
    73      *
    7469     * @param string $string
    7570     * @param int    $num_words
     
    7772     *
    7873     * @return false|string
     74     * @see   wp_trim_words();
     75     * @since 3.0
    7976     */
    8077    public function trim_words( $string = '', $num_words = 30, $more = null ) {
    81         if ( ! $string ) {
     78        if ( $this->is_empty( $string ) ) {
    8279            return false;
    8380        }
     
    144141    /**
    145142     * Get RGB values from a hex color string
    146      * @since 3.0
    147143     *
    148144     * @param string $hex Valid hex color
    149145     *
    150146     * @return array
     147     * @since 3.0
    151148     */
    152149    public function hex_to_rgb( $hex ) {
     
    158155    /**
    159156     * Get contrasting hex color based on given hex color
    160      * @since 3.0
    161157     *
    162158     * @param string $hex Valid hex color
    163159     *
    164160     * @return string
     161     * @since 3.0
    165162     */
    166163    public function hex_get_contrast( $hex ) {
     
    172169
    173170    /**
     171     * @param string $url
     172     *
     173     * @return bool
    174174     * @since 1.2.0
    175      *
    176      * @param string $url
    177      *
    178      * @return bool
    179175     */
    180176    public function is_image( $url ) {
     
    185181        $ext = strtolower( pathinfo( strtok( $url, '?' ), PATHINFO_EXTENSION ) );
    186182
    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    /**
    193187     * @param string $string
    194188     *
    195189     * @return array
     190     * @since 3.0
    196191     */
    197192    public function comma_separated_to_array( $string ) {
    198         $array = array();
     193        $array = [];
    199194        if ( is_scalar( $string ) ) {
    200195            if ( strpos( $string, ',' ) !== false ) {
    201196                $array = array_filter( explode( ',', ac_helper()->string->strip_trim( str_replace( ' ', '', $string ) ) ) );
    202197            } else {
    203                 $array = array( $string );
     198                $array = [ $string ];
    204199            }
    205200        } else if ( is_array( $string ) ) {
     
    211206
    212207    /**
    213      * @since 3.0
    214      *
    215208     * @param string $string
    216209     *
    217210     * @return array
     211     * @since 3.0
    218212     */
    219213    public function string_to_array_integers( $string ) {
    220         $integers = array();
     214        $integers = [];
    221215
    222216        foreach ( $this->comma_separated_to_array( $string ) as $k => $value ) {
     
    230224
    231225    /**
    232      * @since 3.0
    233      *
    234226     * @param string $hex Color Hex Code
    235227     *
    236228     * @return string
     229     * @since 3.0
    237230     */
    238231    public function get_color_block( $hex ) {
     
    286279     */
    287280    public function is_not_empty( $value ) {
    288         return $value || 0 === $value;
     281        return $value || 0 === $value || '0' === $value;
    289282    }
    290283
Note: See TracChangeset for help on using the changeset viewer.