Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-10-31 13:18:55

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Plugin for other permalinks mode?

Hello,

on my sites I use another permalink mode than the standard (title_id_category1.html). At the moment I patch textpattern, but I would like to implement it in a more elegant way over a plugin. I know gbp_permanent_links, but I don’t want to use slashes in my urls.

Can someone give me a hint? Thanks!

See the actual patches …

textpattern/include/txp_prefs.php

                       'year_month_day_title' => gTxt('year_month_day_title'),
                        'section_title'        => gTxt('section_title'),
                        'title_only'           => gTxt('title_only'),
+                       'title_id'             => gTxt('title_id'),
                        // 'category_subcategory' => gTxt('category_subcategory')
                );

textpattern/lib/txplib_publish.php

        $qs = strpos($req,'?');
        if ($qs) $req = substr($req, 0, $qs);
        $req = preg_replace('/index\.php$/', '', $req);
+       $req = preg_replace('/\_/', '/', $req);
        $r = array_map('urldecode', explode('/',$req));
        $o['u0'] = (isset($r[0])) ? $r[0] : '';
        $o['u1'] = (isset($r[1])) ? $r[1] : '';

textpattern/publish/taghandlers.php

                                       $out = hu."$thisid/";
                                }
                                break;
+ 
+                       case 'title_id':
+                               if ($prefs['attach_titles_to_permalinks'])
+                               {
+                               if (empty($category1) && isset($Category1)){ $category1 = $Category1;} elseif (!empty($category1)) {} else {$category1 = '';} 
+                                       $out = hu."$url_title"."_"."$thisid"."_".mb_strtolower(str_replace(array(' & ',' \& ',' & ',' & ','/',' '),'-',fetch_category_title($category1)."_".$section.".html"));
+                               }else{
+                               $out = hu."$thisid/";
+                               }
+                       break;
+ 
                        case 'section_title':
                                $out = hu."$section/$url_title";
                                break;

textpattern/publish.php

                                                                        $is_404 = empty($out['s']);
                                                                }
                                                        break;
+ 
+                                                       case 'title_id':
+                                                               if (is_numeric($u2) && ckExID($u2))
+                                                               {
+                                                                       $rs = lookupByID($u2);
+                                                                       $out['id'] = (!empty($rs['ID'])) ? $rs['ID'] : '';
+                                                                       $out['s'] = (!empty($rs['Section'])) ? $rs['Section'] : '';
+                                                                       $is_404 = (empty($out['s']) or empty($out['id']));
+                                                               }else{
+                                                                       # We don't want to miss the /section/ pages
+                                                                       $out['s']= ckEx('section',$u1)? $u1 : '';
+                                                                       $is_404 = empty($out['s']);
+                                                               }
+                                                       break;
                                                }
                                                if (!$is_404) {
                                                        $out['context'] = validContext($out['context']);

Offline

#2 2013-10-31 15:19:50

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Plugin for other permalinks mode?

You pretty much can’t. Textpattern doesn’t offer routing features that could be extended. The only ways to change where URLs lead, is by altering HTTP query string, and the request_uri.

The only extensible thing that core supports when it comes to URLs, is permlink tags handler function… and that is limiting too since it doesn’t use callbacks, but preference string that is converted to function call.

See rah_pathway for some example code. Its my old experiment that allows using anything as a section or an article URL. I wrote more about the plugin in my development blog, and the post URL itself is constructed using it.

The same practice would apply to any other routing practice; alter requested parameters and URI, set handler function.

Offline

#3 2013-11-02 10:47:35

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Re: Plugin for other permalinks mode?

thank you, Jukka. So I have to deal further with my patches …

Offline

Board footer

Powered by FluxBB