public function prepareSlugForPersist($title, $slug, $id=false)
    {
        $separator = '-';

        if ($slug == "")
        {
            // No slug.. so this is a "create" form; or, the slug was deleted accidentally and so needs to be regenerated

            // Convert all dashes/underscores into separator
            $flip = $separator == '-' ? '_' : '-';

            // wash the title
            $title = html_entity_decode($title);
            $title = strip_tags($title);
            $title = filter_var($title, FILTER_SANITIZE_STRING);
            // remove the encoded blank chars
            $title = str_replace("\xc2\xa0",'',$title);
            // remove encoded apostrophe
            $title = str_replace("&#39;",'',$title);
            $title = trim($title);

            $slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);

            // Remove all characters that are not the separator, letters, numbers, or whitespace.
            $slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));

            // Replace all separator characters and whitespace by a single separator
            $slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);

            // well, is another record using this slug already? Let's return a record count, so we can use the count number...
            $rowCount = $this->doesSlugAlreadyExist($slug);

            if ($rowCount > 0)
            {
                // yes, this slug does exist already, so let's append this slug to make it different from what already exists.
                ++$rowCount;
                return $slug.$rowCount;
            }

            // no, this slug does not yet exist, so let's use it as-is...
            return $slug;
        }


        // Ah, so a slug was entered. So coming from an "edit" form...

        // remove the encoded blank chars
        $slug = str_replace("\xc2\xa0",'',$slug);

        // remove encoded apostrophe
        $slug = str_replace("&#39;",'',$slug);

        $slug = trim($slug);
        $slug = strtolower($slug);
        $slug = strip_tags($slug);
        $slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);


        // if this slug is a different slug manually entered into the edit form, then process it further
        if (!$this->isManuallyChangedSlugInEditForm($slug, $id)) {
            return $slug;
        }

        // so this slug does belong to the existing ID, but is different than the slug in the database...

        // well, is another record using this slug already? Let's return a record count, so we can use the count number...
        $rowCount = $this->doesSlugAlreadyExist($slug);

        if ($rowCount > 0)
        {
            // yes, this slug does exist already, so let's append this slug to make it different from what already exists.
            ++$rowCount;
            return $slug.$rowCount;
        }

        // no, this slug does not yet exist, so let's use it as-is...
        return $slug;
    }
public function prepareSlugForPersist($title, $slug, $id=false)
    {
        $separator = '-';

        if ($slug == "")
        {
            // No slug.. so this is a "create" form; or, the slug was deleted accidentally and so needs to be regenerated

            // Convert all dashes/underscores into separator
            $flip = $separator == '-' ? '_' : '-';

            // wash the title
            $title = html_entity_decode($title);
            $title = strip_tags($title);
            $title = filter_var($title, FILTER_SANITIZE_STRING);
            // remove the encoded blank chars
            $title = str_replace("\xc2\xa0",'',$title);
            // remove encoded apostrophe
            $title = str_replace("&#39;",'',$title);
            $title = trim($title);

            $slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);

            // Remove all characters that are not the separator, letters, numbers, or whitespace.
            $slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));

            // Replace all separator characters and whitespace by a single separator
            $slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);

            // well, is another record using this slug already? Let's return a record count, so we can use the count number...
            $rowCount = $this->doesSlugAlreadyExist($slug);

            if ($rowCount > 0)
            {
                // yes, this slug does exist already, so let's append this slug to make it different from what already exists.
                ++$rowCount;
                return $slug.$rowCount;
            }

            // no, this slug does not yet exist, so let's use it as-is...
            return $slug;
        }


        // Ah, so a slug was entered. So coming from an "edit" form...

        // remove the encoded blank chars
        $slug = str_replace("\xc2\xa0",'',$slug);

        // remove encoded apostrophe
        $slug = str_replace("&#39;",'',$slug);

        $slug = trim($slug);
        $slug = strtolower($slug);
        $slug = strip_tags($slug);
        $slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);


        // if this slug is a different slug manually entered into the edit form, then process it further
        if (!$this->isManuallyChangedSlugInEditForm($slug, $id)) {
            return $slug;
        }

        // so this slug does belong to the existing ID, but is different than the slug in the database...

        // well, is another record using this slug already? Let's return a record count, so we can use the count number...
        $rowCount = $this->doesSlugAlreadyExist($slug);

        if ($rowCount > 0)
        {
            // yes, this slug does exist already, so let's append this slug to make it different from what already exists.
            ++$rowCount;
            return $slug.$rowCount;
        }

        // no, this slug does not yet exist, so let's use it as-is...
        return $slug;
    }
public function prepareSlugForPersist ( $ title , $ slug , $ id = false ) { $ separator = '-' ; if ( $ slug == "" ) { // No slug.. so this is a "create" form; or, the slug was deleted accidentally and so needs to be regenerated // Convert all dashes/underscores into separator $ flip = $ separator == '-' ? '_' : '-' ; // wash the title $ title = html_entity_decode ( $ title ) ; $ title = strip_tags ( $ title ) ; $ title = filter_var ( $ title , FILTER_SANITIZE_STRING ) ; // remove the encoded blank chars $ title = str_replace ( "\xc2\xa0" , '' , $ title ) ; // remove encoded apostrophe $ title = str_replace ( "&#39;" , '' , $ title ) ; $ title = trim ( $ title ) ; $ slug = preg_replace ( '![' . preg_quote ( $ flip ) . ']+!u' , $ separator , $ title ) ; // Remove all characters that are not the separator, letters, numbers, or whitespace. $ slug = preg_replace ( '![^' . preg_quote ( $ separator ) . '\pL\pN\s]+!u' , '' , mb_strtolower ( $ slug ) ) ; // Replace all separator characters and whitespace by a single separator $ slug = preg_replace ( '![' . preg_quote ( $ separator ) . '\s]+!u' , $ separator , $ slug ) ; // well, is another record using this slug already? Let's return a record count, so we can use the count number... $ rowCount = $ this -> doesSlugAlreadyExist ( $ slug ) ; if ( $ rowCount > 0 ) { // yes, this slug does exist already, so let's append this slug to make it different from what already exists. ++ $ rowCount ; return $ slug . $ rowCount ; } // no, this slug does not yet exist, so let's use it as-is... return $ slug ; } // Ah, so a slug was entered. So coming from an "edit" form... // remove the encoded blank chars $ slug = str_replace ( "\xc2\xa0" , '' , $ slug ) ; // remove encoded apostrophe $ slug = str_replace ( "&#39;" , '' , $ slug ) ; $ slug = trim ( $ slug ) ; $ slug = strtolower ( $ slug ) ; $ slug = strip_tags ( $ slug ) ; $ slug = preg_replace ( '![' . preg_quote ( $ separator ) . '\s]+!u' , $ separator , $ slug ) ; // if this slug is a different slug manually entered into the edit form, then process it further if ( ! $ this -> isManuallyChangedSlugInEditForm ( $ slug , $ id ) ) { return $ slug ; } // so this slug does belong to the existing ID, but is different than the slug in the database... // well, is another record using this slug already? Let's return a record count, so we can use the count number... $ rowCount = $ this -> doesSlugAlreadyExist ( $ slug ) ; if ( $ rowCount > 0 ) { // yes, this slug does exist already, so let's append this slug to make it different from what already exists. ++ $ rowCount ; return $ slug . $ rowCount ; } // no, this slug does not yet exist, so let's use it as-is... return $ slug ; }
Prepare slug for persist.

@param  text  $title
@param  text  $slug
@param  int   $id        The id of the record (eg, of the posts table) that is currently being edited
@return text
Prepare slug for persist .