1 edb Sep 06, 2005 19:27
3 blueyed Aug 04, 2006 22:48
You should use $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] instead. It's the "new" PHP way.
(just in case the above does not work, what it won't on a recent PHP installation).
4 john Aug 05, 2006 03:25
@blueyed
What do you mean by "RECENT PHP installation?
The Code has worked fine in the last 3 versions of B2evo although I don't have PHP 5
5 blueyed Aug 05, 2006 03:30
It's just the register_globals setting, which you could still enable in PHP 5, but is off by default since 4.3 or 4.2 or something.
6 john Aug 05, 2006 07:14
Works just fine. Thanks blueyed
7 john Sep 05, 2006 15:16
While the
<?php
$url = sprintf("%s%s%s","http://",$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI']);
?>
<a href="<?php echo $url ?>#top" title="Jump to Page Top">Page top</a>
works fine, is there any way of converting any "&"'s in the URL to "&"'s in the actual Page Top and Page Bottom links. ?
8 blueyed Sep 05, 2006 18:27
Use <?php echo htmlspecialchars($url); ?>
9 john Sep 05, 2006 22:12
Thats the one... thank you blueyed
10 moonchild Aug 04, 2007 22:03
Instead of adding the jump to top link to each skin, I've incorporated it into the core, in the item_funcs.php file:
/**
* Links to previous/next page
*
* Note: remove this tag from skin template if you don't want this functionality
*
* @todo move to ItemList
*/
function posts_nav_link($sep=' :: ', $prelabel='#', $nxtlabel='#', $page='')
{
global $p, $Settings, $MainList;
$jumpurl = sprintf("%s%s%s","http://",$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI']);
if( !empty( $MainList->sql ) && empty($p) )
{
$max_paged = $MainList->total_pages;
if( $max_paged > 1 )
{
previous_posts_link( $prelabel, $page );
echo $sep.'<a href="'.$jumpurl.'#top">Jump to top</a>'.$sep;
next_posts_link( $nxtlabel, $max_paged, $page );
}
}
}
Very handy! As long as I don't forget to keep including the anchor!
11 balupton Aug 04, 2007 22:11
REQUEST_URI is only for apache installs, I you need to use script_name and query_string for IIS installs.
I actually have this mammoth inside my resource library.
function selfURL() {
$s = empty($_SERVER['HTTPS']) ? ''
: ($_SERVER['HTTPS'] == 'on') ? 's'
: '';
$protocol = strleft(strtolower($_SERVER['SERVER_PROTOCOL']), '/').$s;
$port = ($_SERVER['SERVER_PORT'] == '80') ? ''
: (':'.$_SERVER['SERVER_PORT']);
$last_part = (!empty($_SERVER['REQUEST_URI']) ? (strpos($_SERVER['REQUEST_URI'], '?') !== false ? $_SERVER['REQUEST_URI'] : $_SERVER['REQUEST_URI'].'?') : $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
return $protocol.'://'.$_SERVER['SERVER_NAME'].$port.$last_part;
}
But isn't top a browser known thing, like I never thought you had to include a actual anchor for it...
12 moonchild Aug 04, 2007 22:54
I spoke too soon, because naturally it shows up in the post_nav_link at the top of my sidebar. Oops! So instead I've changed it in the _main.php file at the bottom of the bPosts div to:
<?php posts_nav_link(' :: <a href="'.$jumpurl.'#top">Jump to top</a> :: ' ); ?>
Guess I'll have to keep doing it in each skin. What I'd really like to have would be a global footer, but it's just not working out that way for me. For example, I tried to write a display_validations function, where I could then just put a 1 or 0 for each button. But it only worked on the XHTML and CSS, not on the ATOM and RSS. Also, I'd rather add the contact_link to a footer and add it to every skin. Ah, well, somewhen.
13 moonchild Aug 04, 2007 23:02
balupton wrote:
REQUEST_URI is only for apache installs, I you need to use script_name and query_string for IIS installs.
I actually have this mammoth inside my resource library.
Okay, where's the best place for it? Do I have to load down every _main.php file I have, or can I stick it in the item_funcs file, or footer, or is there a better suggestion?
But isn't top a browser known thing, like I never thought you had to include a actual anchor for it...
Not my browser. = /
14 balupton Aug 04, 2007 23:08
Well if the other script was working then you have a apache server, so doesn't really matter, just that not everyone does, in which the function I posted comes in handy.
15 moonchild Aug 04, 2007 23:53
Well, naturally, I want it to work for everybody. Or at least for those four people who visit my blog. I think I'll be working on a comprehensive footer this weekend.
16 balupton Aug 05, 2007 00:05
:) It will work for everyone that visits your blog, however if you re-installed your blog on a IIS server, then you will run into trouble.
<snip>
Many thanks for this, will try it later today.
Cheers,
ahxcjb