Moving from WordPress - Permalinks Changed

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
chickens
Regular
Posts: 192
Joined: Wed Dec 06, 2006 12:15 am
Location: Vegas
Contact:

Moving from WordPress - Permalinks Changed

Post by chickens »

I am just moving away from WordPress and got most of the site up and running with no problems at all. The only thing that I have ran into is that the permalinks have changed. I've changed the format of them to match the WP style, but it seems that s9y's titles are capitalized while WP's are not. I've tried the extension for custom permalinks but that seems to require .htm or .html at the end of the link.

The real question, is there a way to make the title:
my.domain.com/year/month/day/This-is-a-Pages-Title
turn into
my.domain.com/year/month/day/this-is-a-pages-title

the current setting in the config
%year%/%month%/%day%/%title%

I have no problem at all editing any of the source files or creating my own plugin if thats what needs to happen.

Thanks,
Zac Garrett
A new s9y user
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Moving from WordPress - Permalinks Changed

Post by garvinhicking »

Hi!

Hm, sadly I know of no easy way to make a plugin do that for you.

But since you're willing to patch code, this is what I'm suggesting you. :)

Open your include/functions_permalinks.inc.php file. Find this:

Code: Select all

function serendipity_archiveURL($id, $title, $key = 'baseURL', $checkrewrite = true, $entryData = null) {
    global $serendipity;
    $path = serendipity_makePermalink($serendipity['permalinkStructure'], array('id'=> $id, 'title' => $title, 'entry' => $entryData));
    if ($checkrewrite) {
        $path = serendipity_rewriteURL($path, $key);
    }
    return $path;
}
replace it with:

Code: Select all

function serendipity_archiveURL($id, $title, $key = 'baseURL', $checkrewrite = true, $entryData = null) {
    global $serendipity;
    $title = strtolower($title);
    $path = serendipity_makePermalink($serendipity['permalinkStructure'], array('id'=> $id, 'title' => $title, 'entry' => $entryData));
    if ($checkrewrite) {
        $path = serendipity_rewriteURL($path, $key);
    }
    return $path;
}
That "strtolower" insertion should be what you're after, I hope. :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Garvin, since Serendipity is so obviously superior, I'm expecting a rush of WordPress and other users once word gets out. I propose we add an additional parameter to the permalink structure: %lowertitle%. I think this would help migrating users, since they won't have to lose their search engine ranking or modify existing bookmarks.
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

That's a good idea. A patch would be this:

Code: Select all

Index: include/functions_permalinks.inc.php
===================================================================
--- include/functions_permalinks.inc.php	(revision 1520)
+++ include/functions_permalinks.inc.php	(working copy)
@@ -505,7 +505,7 @@
  */
 function serendipity_makePermalink($format, $data, $type = 'entry') {
     global $serendipity;
-    static $entryKeys    = array('%id%', '%title%', '%day%', '%month%', '%year%');
+    static $entryKeys    = array('%id%', '%lowertitle%', '%title%', '%day%', '%month%', '%year%');
     static $authorKeys   = array('%id%', '%username%', '%realname%', '%email%');
     static $categoryKeys = array('%id%', '%name%', '%description%');
 
@@ -523,10 +523,14 @@
 
             $ts = serendipity_serverOffsetHour($data['entry']['timestamp']);
 
+            $ftitle  = serendipity_makeFilename($data['title']),
+            $fltitle = strtolower($ftitle);
+
             $replacements =
                 array(
                     (int)$data['id'],
-                    serendipity_makeFilename($data['title']),
+                    $fltitle,
+                    $ftitle,
                     date('d', $ts),
                     date('m', $ts),
                     date('Y', $ts)
@@ -568,8 +572,8 @@
  * @return  string      The regular expression to a permalink URL
  */
 function serendipity_makePermalinkRegex($format, $type = 'entry') {
-    static $entryKeys           = array('%id%',     '%title%',              '%day%',      '%month%',    '%year%');
-    static $entryRegexValues    = array('([0-9]+)', PAT_FILENAME_MATCH, '[0-9]{1,2}', '[0-9]{1,2}', '[0-9]{4}');
+    static $entryKeys           = array('%id%',     '%lowertitle%',     '%title%',          '%day%',      '%month%',    '%year%');
+    static $entryRegexValues    = array('([0-9]+)', PAT_FILENAME_MATCH, PAT_FILENAME_MATCH, '[0-9]{1,2}', '[0-9]{1,2}', '[0-9]{4}');
 
     static $authorKeys          = array('%id%',     '%username%',           '%realname%',           '%email%');
     static $authorRegexValues   = array('([0-9]+)', PAT_FILENAME_MATCH, PAT_FILENAME_MATCH, PAT_FILENAME_MATCH);

But I don't dare to commit this to the 1.1 release tree because of possible borkage. So I just created the 1.2 branch for s9y :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
chickens
Regular
Posts: 192
Joined: Wed Dec 06, 2006 12:15 am
Location: Vegas
Contact:

Post by chickens »

Garvin, thanks. I will try this later today when I get a chance and report back.

Thanks,
Zac
chickens
Regular
Posts: 192
Joined: Wed Dec 06, 2006 12:15 am
Location: Vegas
Contact:

Post by chickens »

Okay, so I couldn't wait.

I've now got my links from google and other search engines back to a working state. I used strtolower as was suggested and also had to add a slash at the end of the permalinks to exactly match my old links.

current format: %year%/%month%/%day%/%title%/

Thanks,
Zac
chickens
Regular
Posts: 192
Joined: Wed Dec 06, 2006 12:15 am
Location: Vegas
Contact:

Post by chickens »

It is seeming that WP removes non alpha-numeric info from their permalinks. On my site the title of one of my posts includes a + and = which WP ignores. Serendipity removes the equal (+) but not the plus (+). I personally do not mind a few things being broken as my site is not old enough to have it matter all that much. I am just posting as a FYI to future WP to s9y users.

Since we are talking about WP to s9y I think that is also worth mentioning that when importing data the database user needs to have access to both databases. A simple one liner in the import tool would have saved me a bit of time trying to figure it out.

I will keep reporting back if I find problems/differences so that you can make it as simple as possible to get WP converts like myself.

Thanks,
Zac
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi chickens!

You can change the characters that are translated in the same functions_permalinsk.inc.php file - see the first function "serendipity_makeFilename". There you could add also "+" to the list of chraracters that get replaced/removed.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
chickens
Regular
Posts: 192
Joined: Wed Dec 06, 2006 12:15 am
Location: Vegas
Contact:

Post by chickens »

When I added the + to the array the links changed, but the actual pages did not. I tried to update my .htaccess file by changing the permalink structure in the admin, but that didn't get the links working. I will play around with this much more tonight or tomorrow as I've got the day off of work.

Thanks for your help.
Zac
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Ah, okay, it could be that changing that function would not rebuild all the permalinks. You can force rebuilding all permalinks by changing one of the patterns in the configuration, save, and then change it back to the proper path...

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
chickens
Regular
Posts: 192
Joined: Wed Dec 06, 2006 12:15 am
Location: Vegas
Contact:

Post by chickens »

Perfect!

I knew it was something simple that I wasn't thinking of.

Thanks again,
Zac
Post Reply