Permalink batch

23 posts by 7 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: July 15, 2015   (RSS)

By Dave - June 18, 2015

Hi Guys, Just wanted to let you know I've got this in the queue and working on an beta release.  Stay tuned.

Dave Edis - Senior Developer
interactivetools.com

By Maurice - July 6, 2015

Great any idea when? for a release date?

-------------------------------------------

Dropmonkey.nl

By admin - July 8, 2015

Sorry for the delay!  Almost done, should be able to post it tomorrow, and then a CMSB alpha release after that.  Stay tuned and thanks for the reminder.

By Dave - July 8, 2015 - edited: July 8, 2015

Logged in with the wrong account.  That was posted by me...  :-)

Dave Edis - Senior Developer
interactivetools.com

By Dave - July 9, 2015

Hi Guys, 

Here's a download link for the beta: http://www.interactivetools.com/add-ons/download.php?num=1071&beta=1

I ended up rewriting a lot more of the code.  Here's the changelog: 

*** July 9, 2015 - Version 1.03 Released

SERVER REQUIREMENTS: Requires CMS v2.65

NEW FEATURES
- Plugin Menu: Added option 'Update Tables' to automatically generate permalinks for an entire section
- Code Generator: New optional code generated to force redirects to www. domain to prevent duplicate urls (SEO optimization)
- Readme.txt: Added new section: Advanced - Creating custom permalink formats on record save with a plugin

CODE CHANGES & BUG FIXES
- Programmers: Added functions permalink_generate() and permalink_add() for manually creating permalinks (see example below)
- Edit Menus: Field prefix and description fields (from field editor) now show before and after permalinks field (previously only showed /)
- Misc Code and other minor improvements

Here's an easy way to upgrade: 

  • Backup your site (Backup through CMSB and download your site via FTP) Almost never needed but always a good practice, you might end up using the backup next week if your server hard drive crashes.
  • Say your existing folder is /plugins//permalinks/, upload the new files as /permalinks_new/
  • When ready, rename /permalinks/ to /perlmalinks_old/ and /permalinks_new/ to /permalinks/
  • Test everything works as intended, if you have any problems, just rename the folders back and you'll be back on the older version.

We're running this live on interactivetools.com and I used the "Update Table" command under the plugins menu to auto-fill some of the addons that didn't have permalinks yet.  It worked great.

This version also a "Debug Output" link.  If your server has trouble finding the permalinks you can email me that debug output and we can update our code to make sure it works for your server. 

Also, I changed a bit with how website prefixes work /~clientName/actual-site-here/ so if you have that setup let me know if it's working correctly.

Thanks!  Let me know any questions or feedback.

Dave Edis - Senior Developer
interactivetools.com

By Djulia - July 10, 2015

Hi Dave,

Debug Output gives this error:

E_WARNING: preg_match() expects parameter 2 to be string, array given

Array
(
    [logType] => runtime
    [errno] => 2
    [errstr] => preg_match() expects parameter 2 to be string, array given
    [errfile] => permalinks_dispatcher.php
    [errline] => 63
    [errcontext] => *** in symbol table field above ***
)

Thanks!

Djulia

By Djulia - July 10, 2015

Hi Dave,

I obtain also this error on errors 404.

buy.php page does not exist on the server.

[SCRIPT_URL] => /buy.php
[SCRIPT_URI] => http://www.mydomain.com/buy.php

Array
(
    [logType] => runtime
    [errno] => 2
    [errstr] => preg_match() expects parameter 2 to be string, array given
    [errfile] =>permalinks_dispatcher.php
    [errline] => 42
    [errcontext] => *** in symbol table field above ***
)

Thanks!

Djulia

By Dave - July 10, 2015

Thanks Djulia, 

Looks like there is an unexpected array in $_SERVER.  Can you send me the "symbol table" values for $_SERVER from the error log record? 

Feel free to email direct: dave@interactivetools.com

Thanks!

Dave Edis - Senior Developer
interactivetools.com

By Dave - July 10, 2015

Thanks for your email, Djulia,

It's because you have a PHP.ini setting register_argc_argv enabled that adds an array with argv (command line arguments) to $_SERVER.  I didn't know about that possibility so it's a good find!

In permalinks_dispatcher.php:

Search for getCurrentUserFromCMS and replace this: 

if (preg_match("/non-existant-url/", $value)) {
  $CMS_USER = getCurrentUserFromCMS();

With this:

if (!is_array($value) && preg_match("/non-existant-url/", $value)) {
  $CMS_USER = getCurrentUserFromCMS();

Search for ksort and replace this: 

ksort($_SERVER);
foreach ($_SERVER as $key => $value) {
  if (preg_match("/ORIG|PATH_INFO|QUERY|REDIRECT|SCRIPT|URI|URL/i", $key) || preg_match("/non-existant-url|permalinks/", $value)) {
  $debugInfo[$key] = $value;
  }
}

With this:

ksort($_SERVER);
foreach ($_SERVER as $key => $value) {
  $keyMatches = preg_match("/ORIG|PATH_INFO|QUERY|REDIRECT|SCRIPT|URI|URL/i", $key);
  $valueMatches = !is_array($value) && preg_match("/non-existant-url|permalinks/", $value);
  if ($keyMatches || $valueMatches) { $debugInfo[$key] = $value; }
}

Can you let me know if that fixes it for you?

Thanks!

Dave Edis - Senior Developer
interactivetools.com