Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-03-10 23:46:52

lindabb
Member
Registered: 2023-02-17
Posts: 111

not related id

Hi,
I’m working on part 2 , user profile, basically I have users login to their own profile, unfortunately they have old link to profile like this:
mysite.com/user/profile?login=p&id=use_id
also I user that id in many places
I was able to get till mysite.com/user/profile?login=p no issue, but when comes to ID in url, textpattern treat the id as article id.
How I accomplish this in textpattern by passing article ids and use user id ?

I hope there is work around, otherwise , I will create php outside textpattern process in a sub folder
Thank you

Offline

#2 2023-03-11 10:37:32

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: not related id

Some URL parameters (id, s and so on) are hardcoded (txp is an old CMS), but there is always a workaround. The most straightforward would be to put the site in a clean URL mode and rewrite id requests via .htaccess if you don’t need users ids. Otherwise, a mini-plugin called on ('pretext_end', '', 1) could do it too, by setting global $pretext['id'] = 0 (untested):

register_callback('pre_test', 'pretext_end', '', 1);

function pre_test($event, $step) {
  global $pretext;

  $pretext['id'] = 0;
  $pretext['s'] = '';
}

Offline

#3 2023-03-11 14:54:03

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: not related id

Thank you,
Sorry to say, didn’t work as expected , all my sections points to default page after I enabled the plugin

\Txp::get('\Textpattern\Tag\Registry')
   ->register('pre_test'); 

      register_callback('pre_test', 'pretext_end');


function pre_test($event, $step) {
  global $pretext;
  $pretext['id'] = 0;
  $pretext['s'] = '';
}

Thank you for your time again

Last edited by lindabb (2023-03-11 15:14:48)

Offline

#4 2023-03-11 15:43:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: not related id

Just a note: the full callback is required with all parameters…

register_callback('pre_test', 'pretext_end', '', 1);

The last number 1 means to run pre, not post Textpattern processing.

Not all callbacks have both pre (1) and post (0) – the default – but in this case it likely makes a difference since you’re altering a fundamental system variable.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2023-03-11 16:09:14

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: not related id

Thank you Bloke,

I fixed that , now works I can see all my pages, but still when I pass id I get page 404 not found

mysite.com/user/profile?login=p works, I can get p
mysite.com/user/profile?login=p&id=125 ( still not working)

BTW: where I need to call my new plugin or no need to call it (loaded with page)

Thank you

Offline

#6 2023-03-11 22:16:35

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: not related id

Strange, everything seems to work fine for me. Not sure it’s related, but

  • you shouldn’t register the tag, remove this: \Txp::get('\Textpattern\Tag\Registry')->register('pre_test');
  • you shouldn’t call it, the plugin is loaded and called automatically.
  • you should put a file containing this code (preceded by <?php) in your plugin cache directory, or ensure it has the Public type if stored in db.

Offline

#7 2023-03-12 14:06:23

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: not related id

Thank you etc,
here is my plugin look like as you suggest:

<?php
register_callback(‘pre_test’, ‘pretext_end’, ‘’, 1);

function pre_test($event, $step) { global $pretext;

$pretext[‘id’] = 0; $pretext[‘s’] = ‘’; }

after I removed
Txp::get(‘\Textpattern\Tag\Registry’)->register(‘pre_test’);
open new window, still not working as my old link:
mysite.com/user/profile?login=p&id=125
notice after profile I have ? this kind id not working

but I tested this link and worked (which not what I’m looking for)
mysite.com/user/profile/login=p&id=125

I guess the only workaround is to add new rule to .htaccess (which I hate to change .htaccess)

I wish to see this option added in upcoming versions and configurable in admin Preferences sure with backward compatibility ! (if doesn’t exists then backward compatible, else set it) something like this.

Thank you all for your help

Offline

#8 2023-03-12 17:38:17

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: not related id

lindabb wrote #335053:

open new window, still not working as my old link:
mysite.com/user/profile?login=p&id=125
notice after profile I have ? this kind id not working

but I tested this link and worked (which not what I’m looking for)
mysite.com/user/profile/login=p&id=125

It looks like your problem now is not id but trailing slashes? Can you access mysite.com/user/profile page at all? If not, try setting Trailing slash preference to Yes (4.9-dev only).

I wish to see this option added in upcoming versions and configurable in admin Preferences sure with backward compatibility ! (if doesn’t exists then backward compatible, else set it) something like this.

Will think on a best way to make core parameters configurable, thank you.

Offline

Board footer

Powered by FluxBB