goo.gl URL shortener

Summary: Provides PHP variable and Page Variable that contains the goo.gl shortened URL for the current page.
Version: 1.0
Prerequisites: PmWiki
Status: Works

Live demonstration: http://fling.seas.upenn.edu/~subhrabh/cgi-bin/wiki/index.php (click the "goo.gl short URL" icon at the upper right corner of the page)

Maintainer: Subhrajit
Categories: Links PageVariables
Users: (view? / edit)
Discussion: GooGlURL-Talk?

Questions answered by this recipe

Q: The URLs in my wiki are quite long. I know that http://goo.gl is a URL shortening service that can help shorten long URLs. However I would automatically like to let the visitors to my Wiki find a short goo.gl URL that they can easily copy/share. How do I do that?
A: This recipe provides the PHP variable $ThisPageGooGlURL and the page variable {$ThisPageGooGlURL} that contains the goo.gl short URL for the current page. You can then use that in the pages or the skin of your Wiki.

Description

Provides a PHP variable and a page variable called "ThisPageGooGlURL" that contains the goo.gl short URL for the current page.

Installation

  1. Copy the attached goo_gl.phpΔ into the /cookbook folder.
  2. In /local/config.php add the line include_once('cookbook/goo_gl.php');
 Warning and Disclaimer:                                                                                                     
    Google and all its related logos & trademarks are properties of Google Inc. (http://www.google.com/)                     
    Your use of Google API and goo.gl service are subject to your agreement of acceptance of Google's terms and conditions.  
        See http://goo.gl/, http://www.google.com/accounts/TOS and http://code.google.com/terms.html for more details.       
    The author of this recipe is not related to Google and does not represent Google.                                 

Use

Use in wiki-text of individual pages:

Just use the page variable "{$ThisPageGooGlURL}" wherever you want the goo.gl URL to appear.

An example of use in the .tmpl file of your Wiki's skin:
[Live demonstration: http://fling.seas.upenn.edu/~subhrabh/cgi-bin/wiki/index.php (click the "goo.gl short URL" icon at the upper right corner of the page)]

1. In the .tmpl file of the skin, where we want the icon to appear, put in the following HTML code:
<span style='position:relative;margin:0;padding:0;'>
    <a href='javascript:ToggleGooGlBox();' title='goo.gl short URL'>
        <img src='$SkinDirUrl/images/goo_gl.png' width=15 height=15 />
    </a>
    <span id='googlbox' onClick='document.getElementById("googltext").select();'>
        Short URL for this page:
        <span style='float:right;'>[<a href='javascript:ToggleGooGlBox();' style='color:#aab;'>close</a>]</span><br/>
        <input type='text' value='{$ThisPageGooGlURL}' id='googltext' /><br/>
        <span class='googlboxfootnote'>Press Ctrl+C to copy</span>
    </span>
</span>
2. The javascript function ToggleGooGlBox() needs to be included in the skin template (either inside the <head> tag of the .tmpl file of inside one of the .js files that the template includes).
function ToggleGooGlBox() {
    var thediv = document.getElementById('googlbox');

    if (thediv.style.display=="block") 
        thediv.style.display="none";
    else {
        thediv.style.display="block";
        thediv.getElementsByTagName("input")[0].select();
    }
}
3. The CSS styles for the elements used in the HTML is to be included in the skin template (either inside the <head> tag of the .tmpl file of inside one of the .css files that the template includes).
span#googlbox {
    position: absolute;
    top: 13px;
    left: 0px;
    width: 200px;
    font-size: 8pt;
    border: solid 1px #ccc;
    padding: 5px;
    margin: 2px;
    background-color: #fff;
    cursor: text;
    display: none;
}

span#googlbox input {
    border: solid 1px #ccc;
    background-color: #eee;
    margin-left: 5px;
    margin-top: 3px;
    width: 180px;
}

span.googlboxfootnote {
    color: #888;
    font-size: 6pt;
    margin-left: 5px;
}

Change log / Release notes

2011-09-20: v1.0 released.

See also

Contributors

Subhrajit -- author

Comments

See discussion at GooGlURL-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.