Recent Topics

1 Oct 14, 2008 18:21    

My b2evolution Version: 2.x

Newbie alert.

I've been playing around with b2evo on a local install, so I can't provide a link to test things out.

After reading over many posts, I decided to approach the set up of my multilingual blog similar to [url=http://forums.b2evolution.net/viewtopic.php?t=9072#42922]this post[/url]. So I will have two blogs - one for all the English posts and one for all the Russian posts.

Currently things are working pretty well using naming conventions and some symlinks. So http://localhost/bloga/ gives me blog1 in English and http://localhost/ru/bloga/ gives me blog2 all in Russian. To take an example, lets say I have a post: test-post-1. I make sure that the URL "filename" is the same for the post in blog1 and blog2. So the full URLs for the two posts would be http://localhost/bloga/test-post-1 and http://localhost/ru/bloga/test-post-1.

What I would like to do is to be able to switch between the two posts quickly. The way I'd like to do this is by using small graphics of two flags - say the us and russian flags. The only difference in the urls is the presence/absence of ru in the URL. So far, this is what I've come up with:

<?php
	$russian = '<a href="http://localhost/ru/" title="Read this page in Russian"><img src="http://localhost/rsc/flags/h10px/ru.gif" alt="Russian"></a>';
	$american = '<a href="http://localhost/" title="View this page in English"><img src="http://localhost/rsc/flags/h10px/us.gif" alt="English"></a>';

	switch (locale_lang(false)) {
		case "ru-RU": 
				echo $russian, $american;
				break;
		default:
		case "en-US": {
				echo $american, $russian;
			}
	}
?>


Right now this is hardcoded to just switch me to the root of the other language. What I need to do is know which page I am currently on, and then add or remove /ru/ from the link before going to it.

Thanks for any help you can provide. b2evo is quite an impressive system.

2 Oct 14, 2008 22:12

One further question. I wrote that the URL "slug" or URL "filename" was the same for the post in the Russian and English blogs. However, it looks like b2evo prevents me from using the same slug. This would make sense if the two posts were in one blog, but they are in two separate blogs. Is there some setting that I am missing to allow me to have a test-post-1 slug in blog1 and a test-post-1 in blog2?

Thanks!

3 Oct 14, 2008 23:50

Hmmm. It seems that no matter how you have your URLs setup, the only important bit of information is the URL slug. For example, I visited two posts on EdB's blog(s):

Post 1: http://wonderwinds.com/hackblog.php/2008/08/17/image-list-widget-hack-for-2-4-2
Post 2: http://wonderwinds.com/weblog.php/2008/10/03/nanowrimo

Then I took the slug from post 1 and put it on the end of post 2, like this:
http://wonderwinds.com/weblog.php/2008/10/03/image-list-widget-hack-for-2-4-2

Instead of throwing up an error page or something (that post doesn't exist in the weblog blog), it ignored everything except for URL slug, and went to Post 1.

For a more extreme example, I'll put the domain name, any blog, some random stuff, and then finish it up with a slug:
http://wonderwinds.com/flightblog.php/this/is/a/test/whydoesitwork/123456/nanowrimo

Judging from this behavior, it makes sense why the URL slug must be unique. However, I'd still prefer if slug duplication was allowed, at least between different blogs.

What is the protocol for filing a feature request? Thanks.

4 Oct 15, 2008 01:03

Welcome to the forums.

I think it's a lot easier to use one b2evo install for English and another one for Russian posts. Then you can use the same url titles in posts, and even hard-code the default locale.

Good luck

5 Oct 15, 2008 02:20

Is that the recommended approach? I was hoping to avoid managing two b2evo installs.

Do you have a link to any public sites you've set up using this approach?

6 Oct 15, 2008 02:35

I don't know such sites, but it doesn't mean you can't make one yourself ;)

But if you still want to stay with one b2evo install you can add something like _ru to Russian url titles.

7 Oct 15, 2008 02:39

Yeah, I was thinking of appending _ru or something like that so the url titles will still be unique.

Any ideas about getting the current url in php so I can tack this on?

8 Oct 15, 2008 02:46

Try this

regenerate_url( 'blog,title,more,c,tb,pb,locale' )

9 Oct 15, 2008 02:57

Here's the function itself

/**
 * Regenerate current URL from parameters
 * This may clean it up
 * But it is also useful when generating static pages: you cannot rely on $_REQUEST[]
 *
 * @param mixed|string (delimited by commas) or array of params to ignore (can be regexps in /.../)
 * @param array|string Param(s) to set
 * @param mixed|string Alternative URL we want to point to if not the current URL (may be absolute if BASE tag gets used)
 * @param string Delimiter to use for multiple params (typically '&amp;' or '&')
 */
function regenerate_url( $ignore = '', $set = '', $pagefileurl = '', $glue = '&amp;' )

10 Oct 15, 2008 03:11

sam2kb wrote:

Try this

regenerate_url( 'blog,title,more,c,tb,pb,locale' )

I'll give that a try. Is this documented anyplace? For example, I'm not sure how to get the blog and title of the post I'm currently on.

11 Oct 15, 2008 05:44

I don't think it's documented.

Current post url and title

echo $Item->get_permanent_url();
echo $Item->title

Current blog url and name

echo $Blog->gen_blogurl();
echo $Blog->name

Current category url and name

$ChapterCache = & get_Cache( 'ChapterCache' );
$Chapter = & $ChapterCache->get_by_ID( $GLOBALS['cat'], false );

echo $Chapter->get_permanent_url();
echo $Chapter>get( 'name' );

12 Oct 15, 2008 12:15

Thank you very much for those tips! I've got it to switch between the appropriate blog now. The last bit of icing on the cake would be to preserve the post the viewer is on if s/he is on a post. I still can't figure out how to do this.

$Blog->gen_blogurl() gives me full URL of the blog and $Item->get_permanent_url() gives me the full URL of the first post displaying.

What I would really like is to only use the $Item->get_permanent_url() when a viewer is viewing a specific single post. For completeness, I suppose I should trap for date archive url, category url, and tag page url as well.

So back to the original question, is there anyway to get the exact URL address that is showing in a browser's address bar? If I could get that, I could whip together some logic to take care of all the specific cases.

13 Oct 15, 2008 15:37

This gives you the right url you can use, but may add additional params to url

regenerate_url( 'blog,title,more,c,tb,pb,locale' )

You can also try this

echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']


Form is loading...