Current url tag

louisbullock / 2011-12-07 00:04:43   

Ok, I'm asking this again, is there a tag for the current url? If there isn't, how could I implement one. I've looked at index.php (in the root) and found code that I think is about tags, but I'm not sure. Vaska told me that I can add a tag for the current url via the database, but I'm not sure where to begin.

I need a tag like < % currenturl % > so that it displays the url that the page is on, so that I can create Facebook and Twitter links, and a permalink.

Read what I mean here.

Please can someone reply ASAP, this is really important to me.

My site is louisbullock.co.cc

Vaska A / 2011-12-07 01:02:04   
  1. <%url%>

http://www.indexhibit.org/tutorial/how-to-write-a-plugin/

louisbullock / 2011-12-07 02:29:19   

I'm reading that now, trying to piece something together (though I have no knowledge of php).

Vaska, I'm wondering if I should just modify this code:


// additional variables // perhaps we should port these differently? $rs['baseurl'] = BASEURL; $rs['basename'] = BASENAME; $rs['basefiles'] = BASEFILES; $rs['gimgs'] = GIMGS;

So it reads:


// additional variables // perhaps we should port these differently? $rs['baseurl'] = BASEURL; $rs['basename'] = BASENAME; $rs['basefiles'] = BASEFILES; $rs['gimgs'] = GIMGS; $rs['*'] = CURRENTURL;

I'm not sure about the asterisk there, but I'm not sure where to put

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

Which I'm told will give the current url.

louisbullock / 2011-12-07 02:51:11   

Here's what I've tried putting together, but I'm certain I'm doing something wrong:

  1. <?php if  defined'SITE'  exit'No direct script access allowed'

/**
* Current Url
*
* Plugin
*
* @version 0.1
* @author Louis Bullock
*/

// Please review the included readme.txt and license.txt files before using this software.

function current_url( $txt=null, $brk=0 ) {
global $rs;
if ($rs['current_url'] != '') {

// Defaults for the variables above.
if ( $brk == null ) $brk = 0;

// Better safe(-ish) than sorry.
strip_tags($txt);

// Determine whether user is adding text and wants a break.
if ( $brk == 1 ) {
$txt = "
$txt";
} elseif ( $txt != null ) {
$txt = " $txt" ;
}

// We will now get the current url, according to the server.
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

// Then, we put together the current url.
$currenturl = "n$url$txt";
}
// Return the current url.
return $currenturl;
}

?>

G470 / 2011-12-07 05:22:06   

... hmmm, this is a bit more simple but it works.
Maybe you can start modifying from this:

<?php


/**

* Current Url
*
* Plugin
*
* @version 0.1
* @author Louis Bullock
*/


// Please review the included readme.txt and license.txt files before using this software.
function current_url() {

// We will now get the current url, according to the server.

$current_url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

// Return the current url.

return $current_url;

}


?>

add the code as plugin.current_url.php to your server and add this into the template where you need it.:

  1. <plug:current_url />
Vaska A / 2011-12-07 05:45:12   
  1. $current_url = BASEURL . $rs['url'];

So easy...

G470 / 2011-12-07 05:55:43   

haha :) ok that´s even better

louisbullock / 2011-12-07 07:18:11   

Thanks Vaska, but where would I put that?

louisbullock / 2011-12-07 07:35:52   

Wait don't worry, already did it.

Now, Vaska, I already know how to use < % BASEURL %>, that's not what I'm asking for, I already know how to get the base url, I'm talking about the url that the browser is currently on, e.g. if I'm on http://louisbullock.co.cc/design/havok/, then I want the tag to display http://louisbullock.co.cc/design/havok/. That way I can do < a href ="< % CURRENT_URL % >" >Permalink to this page< / a >, and it'll display the current url the browser is on (has navigated to and is currently on), that way I can create 'permalinks', like the 'Permalink Post' to the left of this post.

See what I mean? I don't mean to link to the domain/url of the main site, I mean baseurl + any directories navigated to after it.

I hope you get what I mean.

louisbullock / 2011-12-07 07:38:51   

WAIT! Don't worry, figured that one out myself, instead of

  1. $current_url = BASEURL . $rs['url'];

I just used

  1. $current_url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

Which ended up working fine.

louisbullock / 2011-12-07 07:40:55   

So, if it's alright with you, I think the following code should be published in the downloads section (of plugins), as it'd help future users. And I'd title it "plugin.current_url.php".

  1. <code style="overflow:auto;word-wrap:break-word;">
  2. <?php
  3. /**
  4. * Current Url
  5. *
  6. * Plugin
  7. *
  8. * @version 0.1
  9. * @author Louis Bullock
  10. */

// Please review the included readme.txt and license.txt files before using this software.
function current_url() {

// We will now get the current url, according to the server.
$current_url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

// Return the current url.
return $current_url;
}
?>

louisbullock / 2011-12-07 07:42:07   

I mean:


G470 / 2011-12-07 12:54:04   

... what is different from the version I posted?
Funny, this is actually working really good. ty it ;)

  1. function current_url() {
  2. global $rs;
  3. $current_url = BASEURL . $rs['url'];
  4. return $current_url;
  5. }
Vaska A / 2011-12-07 13:19:33   

Or...don't use a plugin at all...

  1. <meta facebook:og:mollarkey:url:whatever value='<%baseurl%><%url%>' />

OMG: OMaaaaaaagod!!! Vaska, you are so smart!
Vaska: No, I only play smart on the internet. I'm really a dumbass.

;)

G470 / 2011-12-08 01:46:09   

Booooo! :D Open Graph that´s too easy!

louisbullock / 2011-12-08 07:25:30   

Guys don't worry it's all sorted out, all works fine. G470, there isn't a difference between what you posted and what I posted, just my name is added (not accurate though, credit goes to you).

This thread has been closed, thank you.