Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pods_clean_name cleanup #3012

Closed
5 tasks done
PodsBot opened this issue Jun 8, 2015 · 6 comments
Closed
5 tasks done

pods_clean_name cleanup #3012

PodsBot opened this issue Jun 8, 2015 · 6 comments
Assignees
Labels
Type: Enhancement Enhancements to features that already exist, but are not major additions
Milestone

Comments

@PodsBot
Copy link
Collaborator

PodsBot commented Jun 8, 2015

pods_clean_name usage and definition needs some tweaking.

function pods_clean_name ( $orig, $lower = true, $trim_underscores = true ) {

@sc0ttkclark sc0ttkclark self-assigned this Jun 8, 2015
@sc0ttkclark sc0ttkclark added this to the Pods 2.5.4 milestone Jun 8, 2015
@sc0ttkclark sc0ttkclark added the Type: Enhancement Enhancements to features that already exist, but are not major additions label Jun 8, 2015
@sc0ttkclark
Copy link
Member

/**
 * Return a lowercase alphanumeric name (with underscores and dashes)
 *
 * @param string $orig Input string to clean
 * @param boolean $lower Force lowercase
 * @param boolean $trim_underscores Whether to trim off underscores
 *
 * @return string Sanitized name
 *
 * @since 1.2.0
 */
function pods_clean_name ( $orig, $lower = true, $trim_underscores = false ) {

    $str = trim( $str );
    $str = preg_replace( "/([^0-9a-zA-Z\-_])/", "", $str );
    $str = preg_replace( "/(_){2,}/", "_", $str );
    $str = preg_replace( "/(-){2,}/", "-", $str );

    if ( $lower ) {
        $str = strtolower( $str );
    }

    if ( $trim_underscores ) {
        $str = trim( $str, '_' );
    }

    return $str;

}

/**
 * Return a lowercase alphanumeric name (with underscores) for safe Javascript variable names
 *
 * @param string $orig Input string to clean
 * @param boolean $lower Force lowercase
 *
 * @return string Sanitized name
 *
 * @since 2.5.4
 */
function pods_js_name( $orig, $lower = true ) {

    $str = pods_clean_name( $orig, $lower );
    $str = str_replace( '-', '_', $str );

    return $str;

}

@sc0ttkclark
Copy link
Member

Assigned to @quasel for PR on 2.x and release/3.0

@sc0ttkclark
Copy link
Member

Added another task for traversal support

@sc0ttkclark sc0ttkclark assigned quasel and unassigned sc0ttkclark Jun 8, 2015
@quasel
Copy link
Member

quasel commented Jun 11, 2015

guess
$str = trim( $str ); should be
$str = trim( $orig );

@sc0ttkclark
Copy link
Member

Yep, sorry about that, coding via a GitHub comment lol

@sc0ttkclark
Copy link
Member

Can you also make this change to https://github.com/pods-framework/pods/blob/master/ui/fields/_db.php

var newval = $( this ).val().toLowerCase().replace( /([- ])/g, '_' ).replace( /([^0-9a-z_])/g, '' ).replace( /(_){2,}/g, '_' ).replace( /_$/, '' );

with:

var newval = $( this ).val().toLowerCase().replace( /(\s)/g, '_' ).replace( /([^0-9a-z_\-])/g, '' ).replace( /(_){2,}/g, '_' ).replace( /_$/, '' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Enhancements to features that already exist, but are not major additions
Projects
None yet
Development

No branches or pull requests

3 participants