Recent Topics

1 Jan 18, 2006 21:24    

Maybe I'm just not understanding how $Item->title('','',false) works but I'm trying to use Post Titles in URLs and for some reason this doesn't work:

urlencode($Item->title('','',false));


For example, if the Post Title was "This Title should NOT have spaces", I want to encode it as: "This+Title+should+NOT+have+spaces".

I'm using Dawn.

2 Jan 19, 2006 06:04

1) It looks like your post titles are being truncated because they're too long. (e.g., your page [url=http://blog.joshuajmorgan.com/quotes.php/2006/01/10/bastard_wants_to_hit_me_spine_by_they_mi]here[/url] seems to have lost the last few chars).

This came up recently, as a question. Have a look [url=http://forums.b2evolution.net/viewtopic.php?p=25642]here[/url] for a solution. (Last entry).

2) I *believe* that b2evo replaces characters and inserts an underscore. You would have to hack a core file in order to replace the underscore with a plus (+). Not a major change, but a core file hack, just the same.

PM me and I'll help you with a solution. ;)

Cheers.

3 Jan 19, 2006 07:56

Ah ya i saw that post about increasing the permalink url length while I was trying to find a solution to my problem, which is a little different.

I guess I could try to come up with a hack (though I still can't find exactly where the spaces are being converted to underscores... i think it's either in _functions.php or _formatting.php).

The main frustration is that I'm still not understanding how exactly $Item->title('','',false) works. The value it returns appears to be a string, but it's different because normal string functions, like urlencode(), have no effect, and you don't even need "echo" to print the string value.

I'm stumped.

But thanx for helping to get the gears turning...

-------
EDIT:

I completely forgot about this problem until I was checking my referer stats today and noticed that someone had visited my site from this thread.

It turns out that I finally figured out the answer to my own question.

$Item->title('','',false) works by returning a series of echos called by the function title() in _class_item.php, which first calls the function format_to_output() in _functions.php (see, i knew it was in _functions.php, i just didn't know where until i found the title function in _class_item.php...)

Long story short, I figured out how to encode title into URL safe xhtml valid strings by adding a case to the function title() in b2evocore/_functions.php:

FIND:

		case 'xmlattr':
			// use as an attribute: strips tags and escapes quotes
			$content = strip_tags($content);
			$content = convert_chars($content, 'xml');
			$content = str_replace('"', '"', $content );
			$content = str_replace("'", ''', $content );
			break;

ADD AFTER:

		case 'urlencode':
			// display in HTML page body: allow full HTML
			$content = convert_chars($content, 'html');
			$content = urlencode($content);
			break;

Then, whenever you want to encode a title (or any other item class variables) just pass the 'urlencode' argument whenever applicable like this:

$Item->title('','',false,'urlencode');

There might be a better way to do this but my way works with only a single edit to a core file.

Now whenever i use $Item->title('','',false,'urlencode'); in URLs, I get xhtml valid urls with spaces replaced by "+"


Form is loading...