Recent Topics

1 May 29, 2007 19:29    

I'm working on a rendering plugin which involves using anchros (a href ane name) to jump around. My problem is that I can't just do <a href="#anchor"> even when there's <a name="anchor"> on the same page because the page rewrote the base url using skin_base_tag(). So when I tried to do <a href="#anchor">, instead of jumping to the same page, I landed on the directory of the skin. So, I (probably) don't have any other choice except to get the absoute url of the current page (which could be the blog or just the item). My problem is.. how do I get it? I seem to can't find it (checked class Item::get_[something]_link() but I don't think that's what I'm looking for)

2 May 29, 2007 22:46

I got that very same problem! And isn't there a way to disable that base-feature... sucks anyway :D

3 May 29, 2007 23:11

This may help get you started, but isn't a total solution.

I use the following to achieve a Page Top link regardless of what page or URL I'm on. It may give you something to work with

<?php
$url = sprintf("%s%s%s","http://",$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI']);
?>
&middot; <a href="<?php echo htmlspecialchars($url); ?>#top" title="Jump to Page Top">Top</a>

4 May 30, 2007 01:12

Wrote a little PHP hack which seems to be a little bit more reliable:

First, insert these two string functions at the top of the template "_main.php":

<?php
function get_link_href ($s_content)
{
# This strict function extracts the hyper reference out of a _conform_ <a> tag (MUST contain href="..." !!!)
$current_string = $s_content;
$a_begin_tag = strpos($current_string,'<a ');

$a_end_tag = strpos($current_string,'>',$a_begin_tag);

$a_content_string = substr($current_string,$a_begin_tag+2,$a_end_tag-$a_begin_tag-2);
$a_content_begin_href = strpos($a_content_string,' href="');

$a_content_end_href = strpos($a_content_string,'"',$a_content_begin_href+7);

$a_content_href_content = substr($a_content_string,$a_content_begin_href+7,$a_content_end_href-$a_content_begin_href-7);

return $a_content_href_content;
}

function get_anchorable_content ($s_content,$s_url)
{
# This function converts relative anchor links within $s_content to absolute links (anchor links using the permalink url $s_url)
$final_string = '';

	for($offset=0;;)
	{
	$current_string = substr($s_content,$offset);
	$a_begin_tag = strpos($current_string,'<a ');

		if(!is_int($a_begin_tag))
		{
		$final_string .= $current_string;
		break;
		}

	$a_end_tag = strpos($current_string,'>',$a_begin_tag);

		if(!is_int($a_end_tag))
		{
		$final_string .= $current_string;
		break;
		}

	$a_content_string = substr($current_string,$a_begin_tag+2,$a_end_tag-$a_begin_tag-2);

	$a_content_begin_href = strpos($a_content_string,' href="');

		if(!is_int($a_content_begin_href))
		{
		$final_string .= substr($current_string,0,$a_end_tag+1);
		$offset += ($a_end_tag+1);
		continue;
		}

	$a_content_end_href = strpos($a_content_string,'"',$a_content_begin_href+7);

		if(!is_int($a_content_end_href))
		{
		$final_string .= substr($current_string,0,$a_end_tag+1);
		$offset += ($a_end_tag+1);
		continue;
		}

	$a_content_href_content = substr($a_content_string,$a_content_begin_href+7,$a_content_end_href-$a_content_begin_href-7);

		if(strlen($a_content_href_content) === 0 || substr($a_content_href_content,0,1) != '#')
		{
		$final_string .= substr($current_string,0,$a_end_tag+1);
		$offset += ($a_end_tag+1);
		continue;
		}

	// # ist erstes adresszeichen;
	$final_string .= substr($current_string,0,$a_begin_tag+2).substr($a_content_string,0,$a_content_begin_href+7).$s_url.'&amp;'.$a_content_href_content.substr($a_content_string,$a_content_begin_href+7+strlen($a_content_href_content)).'>';
	$offset += ($a_end_tag+1);
	}

return $final_string;
}
?>

Then, we use the output buffering to get any kind of html permalink. This must be inserted into the WHILE loop which deals with the posts:

<?php
ob_start();
$Item->permanent_link('whatever');
$current_html_permalink = ob_get_contents();
ob_end_clean();
$current_permalink_url = get_link_href ($current_html_permalink);

ob_start();
$Item->content();
$current_content = ob_get_contents();
ob_end_clean();
?>

$current_html_permalink is the permalink url of the post currently concerned, $current_content is its content.

Now we use our anchor-conversion function from above to generate content which is friendly towards the anchors despite the <base> tag in the header:

<?php
echo get_anchorable_content($current_content,$current_permalink_url);
?>

For me, it works just fine. :)
I'm a newbie concerning b2evo, that's why I made use of this rather complicated output-buffering stuff... ;)
Have fun :D:D

5 May 30, 2007 03:06

Ah, thanks John for the tip. That works!
imjustaguest, I think your php code would have problems then the blog page is displayed instead of the post (instead of jumping to the current page, it will just to the anchor in the page of the post). But that's just upon my inspection, I could be wrong.

6 May 30, 2007 13:07

You're absolutely right.

I use the hack in cooperation with an introduction-generating script which strips off all html tags, that's why there aren't any anchors displayed on the blog page in my blog.

You may use an if construction which checks upon the existence of the "more=1" parameter to find out whether the blog page is displayed or not.

However, if "more=1" is missing, you may change the $current_permalink_url to the blog page url... ;) (don't ask me if there's a function for it - use some dirty string conversion instead .... :D:D:D)

7 May 30, 2007 18:38

<?php
echo '<a href="'.regenerate_url().'"#wherever" title="go wherever">wherever</a>';
?>

;)

¥


Form is loading...