Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#589 2012-02-20 15:54:03

newnoise
Member
Registered: 2011-02-24
Posts: 35

Re: gbp_permanent_links

Hi,

I’m having a problem with the plugin. I use
<txp:if_individual_article><txp:title /> - </txp:if_individual_article>

to dynamically set page titles and descriptions. When I use normal messy-mode urls this works fine. But when I use standard gbp_permant rewriting (http://url.com/section/article) I get errors with the code:

textpattern/lib/txplib_misc.php:2323 trigger_error()
textpattern/publish/taghandlers.php:2270 assert_article()
textpattern/publish.php:1188 title()
textpattern/publish.php:1100 processTags()
textpattern/publish/taghandlers.php:3219 parse()
textpattern/publish.php:1188 if_individual_article()
textpattern/publish.php:1113 processTags()
textpattern/lib/txplib_misc.php:1706 parse()
textpattern/publish/taghandlers.php:314 parse_form()
textpattern/publish.php:1188 output_form()

Fehler im Tag: <b>&lt;txp:title /&gt;</b> -&gt; <b> Textpattern Notice: Artikel-Tags können nicht außerhalb des Artikel-Kontexts benutzt werden. on line 2323</b>
textpattern/lib/txplib_misc.php:2323 trigger_error()
textpattern/publish/taghandlers.php:2270 assert_article()
textpattern/publish.php:1188 title()
textpattern/publish.php:1100 processTags()
textpattern/publish/taghandlers.php:3219 parse()
textpattern/publish.php:1188 if_individual_article()
textpattern/publish.php:1113 processTags()
textpattern/lib/txplib_misc.php:1706 parse()
textpattern/publish/taghandlers.php:314 parse_form()
textpattern/publish.php:1188 output_form()

I’m happy about any help!
Thanks
noise

Last edited by newnoise (2012-02-21 18:09:29)

Offline

#590 2012-04-22 23:17:39

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: gbp_permanent_links

I’ve read through a large part of this thread but I might have missed something obvious:

How do you make your page template respond to custom_field permlink rules?

txp:article doesn’t respond contextually so you need to create an explicit article_custom tag for each custom_field filter. How do you detect:

a) which custom_field filter is currently active?
b) what the custom_field value is?

I can see that there are special tags for text and regex permlink rules using <txp:gbp_if_text and gbp_if_regex for (a) and <txp:page_url type="permlink_text_{$name}" /> and <txp:page_url type="permlink_regex_{$name}" /> for (b). But when I look at the debug output for a custom_field search, I can see only request_uri and req which both contain /section-name/custom-field-value in them but no indication of the custom_field that is being filtered. A lot of other rules also produce similar output for req and request_uri, so it’s hard to isolate when the custom_field applies. I’d really appreciate any tips you might have.


TXP Builders – finely-crafted code, design and txp

Offline

#591 2012-04-23 08:14:42

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: gbp_permanent_links

A small mod to gbp_permanent_links v0.14.7 to allow more than 10 custom fields in the custom_field drop-down:

Find this:

 		// Grab the custom field titles
		$custom_fields = array();
		for ($i = 1; $i <= 10; $i++) {
			if ($v = $prefs["custom_{$i}_set"])
				$custom_fields[$i] = $v;
		}

and replace with this:

		// Grab the custom field titles
		$custom_fields = array();
		$custom_fields_num = count(preg_grep("(^custom_\d+_set$)", array_keys($prefs)));
		for ($i = 1; $i <= $custom_fields_num; $i++) {
			if ($v = $prefs["custom_{$i}_set"])
				$custom_fields[$i] = $v;
		}

The select drop-down now shows all custom fields and the filter works accordingly too.


TXP Builders – finely-crafted code, design and txp

Offline

#592 2012-04-23 08:28:05

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

Re: gbp_permanent_links

jakob wrote:

A small mod to gbp_permanent_links v0.14.7 to allow more than 10 custom fields

Not delved into it but just out of curiosity, can the plugin make use of the core’s getCustomFields() instead (in txplib_misc.php)?

Last edited by Bloke (2012-04-23 08:29:33)


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

#593 2012-04-23 09:22:09

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: gbp_permanent_links

Aside from either routing each custom_field permlink rule to a separate page template or to detect the cryptic value of the permlink_id, I’m stumped, so I resorted to adding some small additional functionality to gbp_permanent_links. If I’ve over-thought this and things can be done more simply, please enlighten me:

The following small patches extend gbp_permanent_links to enable you to detect when a custom_field rule is active, and what the current search value is. Using this information, you can then make txp:article_custom tags with custom field filters:

Patch to output the current custom_field:

Find this part of the plugin code around line 360

case 'custom':
	$custom_options = array_values(array_map(array($this, "encode_url"), safe_column("custom_$custom", 'textpattern', "custom_$custom != ''")));
	if ($this->pref('force_lowercase_urls'))
		$custom_options = array_map("strtolower", $custom_options);
	if (in_array($uri_c, $custom_options)) {
		$match = true;
	}
break;

and add three lines as follows before $match = true;:

case 'custom':
	$custom_options = array_values(array_map(array($this, "encode_url"), safe_column("custom_$custom", 'textpattern', "custom_$custom != ''")));
	if ($this->pref('force_lowercase_urls'))
		$custom_options = array_map("strtolower", $custom_options);
	if (in_array($uri_c, $custom_options)) {
		$custom_name = $prefs["custom_{$custom}_set"];
		$pretext_replacement["permlink_cf"] = $custom_name;
		$pretext_replacement["permlink_cf_{$custom_name}"] = $uri_c;
		$pretext_replacement["permlink_rule"] = 'custom';
		$match = true;
	}
break;

You’ll now have three new pretext values that you can retrieve as follows and use with txp:variable, txp:if_variable:


<txp:page_url type="permlink_rule" /> <!-- returns "custom" when using a custom_field permlink rule -->
<txp:page_url type="permlink_cf" /> <!-- returns the name of the "custom_field" filter in the permlink rule -->
<txp:page_url type="permlink_cf_your-custom-field-name" /> <!-- returns value of custom_field rule currently in the url -->

One last possible addition is the function gbp_if_custom_field which I added here:

function gbp_if_custom_field ($atts, $thing) {
	global $pretext;
	extract(lAtts(array(
		'name' => '',
		'val'  => '',
	),$atts));

	$match = false;
	if (!empty($name)) {
		if (empty($val))
			$match = (isset($pretext["permlink_cf_{$name}"]));
		else
			$match = (@$pretext["permlink_cf_{$name}"] == $val);
	} else {
		$match = (@$pretext["permlink_rule"] == 'custom');
	}
	return parse(EvalElse($thing, $match));
}

It works analogue to gbp_if_text and gbp_if_regex with the additional ability to not specify any attributes if you just want to see if the current search is a custom_field, which can be useful if you want to use smd_multiple_choice in your template:

  • <txp:gbp_if_custom_field> … = is current url a custom_field permlink rule?
  • <txp:gbp_if_custom_field name="my-cf-name"> … = is current url a particular custom_field permlink rule?
  • <txp:gbp_if_custom_field name="my-cf-name" val="value-to-match"> … = does current url match a particular value for the custom_field permlink rule?

All of the above work with <txp:else />.

As an aside: the existing gbp_if_regex and gbp_if_text could also be extended to work without any attribute too by adding $pretext_replacement["permlink_rule"] = 'regex'; and $pretext_replacement["permlink_rule"] = 'text'; to the respective cases earlier in the plugin and an else case at the end of the functions.

Last edited by jakob (2012-04-23 09:51:58)


TXP Builders – finely-crafted code, design and txp

Offline

#594 2012-04-23 09:36:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: gbp_permanent_links

Bloke wrote:

jakob wrote:
A small mod to gbp_permanent_links v0.14.7 to allow more than 10 custom fields

Not delved into it but just out of curiosity, can the plugin make use of the core’s getCustomFields() instead (in txplib_misc.php)?

I delved a bit and think you’re right. Would this be a better replacement for the unlimited custom_fields in the drop-down:

		// Grab the custom field titles
		$custom_fields = getCustomFields();
		foreach ($custom_fields as $i => $name) {
			$custom_fields[$i] = $name;
		}

TXP Builders – finely-crafted code, design and txp

Offline

#595 2012-04-29 18:07:45

mmelon
Member
Registered: 2006-03-02
Posts: 95

Re: gbp_permanent_links

Hi,

I am trying to get a particular url structure by using custom fields.

/custom_1/custom_2/custom_x/…/title

It’s working fine but for the rule to match I have to pad the unused custom fields with something, so a level 1 url might look like this

/custom_1/null/null/title [by entering the word null into the custom fields]

Does anyone know if somewhere late in the matching logic, before the new permlink is returned, if I can str_replace all of the ‘/null’ and get the clean url I am wanting?

Kind regards,
Mike

Offline

#596 2012-04-29 20:28:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: gbp_permanent_links

Not sure if this helps – or if I understood you properly:

but for the rule to match

Do you mean you get no match – i.e. a 404 – or that you get no results from your article_custom tag? You probably know this, but if you set gbp_permlinks pref to debug, you can see the match attempts in the source.

I have to pad the unused custom fields

I’m guessing you mean you put “null” in the segments in the url, not in the actual custom_fields in the articles? And if so, you’re using “null” so that the txp:article_custom tag returns something?

I’m still finding my way around gbp_permanent_links myself so I could be way off here, but thinking aloud, two ideas:

  • If you’re having problems with entering different amounts of url components (e.g. that you have /section///value), you may need to set up a series of rules for each constellation of components and set the precedences so that the deepest url rule is processed first, if that doesn’t apply, then the next and so on… If there is a clear pattern to the order of the rules, you might theoretically be able to tier your rules, e.g. under “destination” redirect the permanent link to another permanent link which has its own rule…
  • Maybe you could achieve the same thing with one or more regex components set to allow certain values, e.g (term-1|term-2|term-3)? You can use gbp_if_regex or txp:page_url type="permlink_regex_{regex-name-from-build-tab}" /> to retrieve which of those terms is in the url and put it in a txp variable. You can then use txp:if_variable, or if you have lots of cases smd_switch to construct your txp:article_custom tag accordingly. That might work depending on how many different potential values you have in your custom_field.

TXP Builders – finely-crafted code, design and txp

Offline

#597 2012-05-05 14:14:56

mmelon
Member
Registered: 2006-03-02
Posts: 95

Re: gbp_permanent_links

Hi,

What I mean by pad the extra custom fields is:

say i have the following rule

custom_1/custom_2/custom_3/title

If I wanted something with 1 less url components to match, I would have to put something in custom_3, so

custom-1: about
custom-2: our-stores
custom-3: .

means that an article called ‘leeds’ gets picked up by rule.

I need each article to match at the deepest level of supported nesting as every other permlink is rewritten according to the depth of the matched url.

If i was on

custom-1:about
title: leeds

or /about/leeds

then every url on the matched page is evaluated against custom-1/title, and rewritten or defaulted back to the standard permlink mode as appropriate. This happens even if some of those urls could match on rules with higher precedence such as

custom-1/custom-2/title

or

custom-1/custom-2/custom-3/title.

To nullify this problem I have been putting ‘.’ in unused custom fields, to always match on the deepest url depth with the most precedence.

This is working, but far from ideal as though the dots are ignored and the urls still resolve as I want, inspecting the source still shows the dots ie

custom-1/custom-2/./title

I’m sure I could prevent the dots from indexing using a canonical tag (or possibly the 301 from the plugin would prevent the bot from seeing them) but I wish it wouldn’t do it.

It would propably cause errors on different platforms (i’m def thinking linux here) and devices anyway.

Does anyone follow what I am trying to achieve?

Thanks jakob for your input thus far.

Kind regards,
Mike

Last edited by mmelon (2012-05-05 14:16:50)

Offline

#598 2012-08-08 14:03:43

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: gbp_permanent_links

I found a bug where by using this plugin we can’t get a link with an hash in the default section.
info and example here

Offline

#599 2012-08-08 14:24:54

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: gbp_permanent_links

You could try wrapping the code you don’t want to be affected by gbp_permanent_links with <txp:gbp_disable_permlinks></txp:gbp_disable_permlinks>.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#600 2012-08-08 15:23:51

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: gbp_permanent_links

maniqui wrote:

You could try wrapping the code you don’t want to be affected by gbp_permanent_links with <txp:gbp_disable_permlinks></txp:gbp_disable_permlinks>.

1. Good to know about it thanks!

2. It’s still not working, try these:

<txp:gbp_disable_permlinks><a href="<txp:site_url />#example">Example</a></txp:gbp_disable_permlinks>

<a href="<txp:gbp_disable_permlinks><txp:site_url />#example</txp:gbp_disable_permlinks>">Example</a>

<a href="<txp:gbp_disable_permlinks><txp:site_url /></txp:gbp_disable_permlinks>#example">Example</a>

<a href="<txp:site_url /><txp:gbp_disable_permlinks>#example</txp:gbp_disable_permlinks>">Example</a>

(not even using a variable LOL)

3. Instead I’m just using relative links now: <a href="/#example">Example</a>

Offline

Board footer

Powered by FluxBB