8 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 17   (RSS)

Hi all,

We've just released a new version of the Permalinks plugin: https://www.interactivetools.com/plugins/permalinks/

NOTE: This version requires CMSB v3.51

This new release has a number of improvements, updated redirect behaviour, simplified generated .htaccess code, and the ability for Update Tables to repopulate the Permalinks DB from existing permalink fields. Check out the plugin changelog for full details.

Let me know any questions or comments!

Daniel
PHP Programmer
interactivetools.com
  1. In the change log it references multi-value urls. What is the use case for this?
  2. Autopopulate_skip words: https://onlinemediamasters.com/why-you-shouldnt-remove-stop-words-from-urls/
  3. What do you mean by 301 redirects are not longer cached? Do you mean that the redirect from the old to the new is no longer in the database? This would be a bad thing. Am I missing something?
------------
Jeff Shields

By kitsguru - April 16 - edited: April 16

One thing I would like to see in the plugin is the ability to combine fields but separate with a slash as well as a space. For instance I have a content_type plus title that I would like to have as

content_type:label/title - in this case I want the label.

I don't see that this needs to be a separate plugin as suggested in another post as it could be part of autopopulate_fromFields. Currently if you add a slash, that combination is ignored and the next one is used.

------------
Jeff Shields

Hi Jeff,

We discussed a few of these already, but I'll answer in full for the benefit of anyone reading:

In the change log it references multi-value urls. What is the use case for this?

This was a fix for custom defined permalinks where the "Custom Target URL" uses multi-value parameters, e.g. "?name[]=value1&name[]=value2"; previously these values were being parsed incorrectly. It might have been a bit more clear to label this a bugfix than "added support".

Autopopulate_skip words:https://onlinemediamasters.com/why-you-shouldnt-remove-stop-words-from-urls/

Thanks for bringing this to our attention - I also did a bit of searching and it looks like there's no longer a penalty by Google for including stopwords in Permalinks. We may consider removing the stopwords altogether in a future release, though in the meantime it should be safe to simply empty out that array to disable the functionality.

What do you mean by 301 redirects are not longer cached?

We made some changes to how we process the 301 redirects so that they should no longer be cached by the browser. 

One thing I would like to see in the plugin is the ability to combine fields but separate with a slash as well as a space.

I'll forward this on to the team as a feature request, thanks for the input! 

Hope this helps answer your questions.

Cheers,

Daniel
PHP Programmer
interactivetools.com

Hi Jeff,

A quick update on your request to add slashes to autopopulate_fromFields: we've come up with what should be a fairly simple way to preserve slashes in the generated permalinks, however, also adding the ability to use list field labels as you specify in your use case is far less trivial. Would you find it useful to have the preserved slashes functionality on its own without the label support? If so I can implement that relatively quickly and provide instructions on how to patch it into the current version. Otherwise, we can keep the whole feature in the request queue.

Thanks,

Daniel
PHP Programmer
interactivetools.com

another use case is date_field/title for blog and events, but need to format the date yyyy-mm-dd

------------
Jeff Shields

Hi Jeff,

I've created an implementation for adding slashes to the generated permalinks. It will require updating permalinks.php in a few places.

First, find the _permalink_generate_getInputText() function - it should be roughly lines 114-129 and looks like this:

// merge input text from one or more input fields, return blank if no populated field combinations or fields found
function _permalink_generate_getInputText($recordOrRequest) {

...

}

Replace the entire function with the following:

// merge input text from one or more input fields, return blank if no populated field combinations or fields found
function _permalink_generate_getInputText($recordOrRequest) {
  
  foreach ($GLOBALS['PERMALINKS']['autopopulate_fromFields'] as $spaceSeparatedFieldSet) {
  
    $inputText = __permalinks_generate_validateFieldSet($recordOrRequest, $spaceSeparatedFieldSet, array(' ', '/'));
    
    if (empty( $inputText )) { continue; } // skip if one or more fields not defined

    // stop after first valid
    break;
  }
  
  return $inputText;
}

// recursively splits out and validates fieldsets based on an array of delimeters
function __permalinks_generate_validateFieldSet( $recordOrRequest, $fieldString, $delimeters ) {
  
  // if no delimeter, stop recursing and check for field in request
  if (empty( $delimeters )) {
    
      if (!array_key_exists($fieldString, $recordOrRequest)) { return false; } // skip if field not defined
      return $recordOrRequest[$fieldString]; // return field value
      
  } else {
    
    $fieldValues = '';
    $delimeter = array_shift( $delimeters ); // get next delimeter, remove from array
    $fieldSet  = array_filter(explode( $delimeter, $fieldString )); // explode fields based on delimeter
    
    // loop through potential fields
    foreach ($fieldSet as $field) {
      
      // recursive call with new field string and reduced delimiter array
      $validatedField = __permalinks_generate_validateFieldSet( $recordOrRequest, $field, $delimeters );
      
      if (empty( $validatedField )) { return false; } // fail if any fields are invalid
      $fieldValues .= $validatedField . $delimeter;   // concatenate field values with delimeter
    }
    
    // remove trailing delimeters
    $fieldValues = rtrim($fieldValues, $delimeter);
  
    return $fieldValues;
    
  }
  
  return false;
  
}

Next, find the line that looks like this (it should be at or near line 206):

$permalinkText = preg_replace('/[^a-z0-9\-\.\_]+/i', '', $permalinkText); // remove non-alphanumeric chars

And replace it with the following:

$permalinkText = preg_replace('/[^a-z0-9\-\.\_\/]+/i', '', $permalinkText); // remove non-alphanumeric chars

With these changes, you should now be able to add values like "field1/field2" to autopopulate_fromFields.

I'd also like to note that this hasn't gone through the official plugin release QA, so I'd recommend first trying this out in a test environment if you're able. Let me know if you have any issues or questions!

Thanks,

Daniel
PHP Programmer
interactivetools.com