<?php

/*
* This is an example file for a public interface and a bookmarklet. It
* is provided so you can build from it and customize to suit your needs.
* It's not really part of the project. Don't submit feature requests
* about this file. It's _your_ job to make it what you need it to be 🙂
*
* Rename to .php
*
*/

// Start YOURLS engine
require_once( dirname(__FILE__).'/includes/load-yourls.php' );

// Change this to match the URL of your public interface. Something like: http://yoursite.com/index.php
$page = YOURLS_SITE . '/sample-public-front-page.php' ;

// Part to be executed if FORM has been submitted
if ( isset( $_REQUEST['url'] ) && $_REQUEST['url'] != 'http://&#039; ) {

// Get parameters — they will all be sanitized in yourls_add_new_link()
$url = $_REQUEST['url'];
$keyword = isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ;
$title = isset( $_REQUEST['title'] ) ? $_REQUEST['title'] : '' ;
$text = isset( $_REQUEST['text'] ) ? $_REQUEST['text'] : '' ;

// Create short URL, receive array $return with various information
$return = yourls_add_new_link( $url, $keyword, $title );

$shorturl = isset( $return['shorturl'] ) ? $return['shorturl'] : '';
$message = isset( $return['message'] ) ? $return['message'] : '';
$title = isset( $return['title'] ) ? $return['title'] : '';

// Stop here if bookmarklet with a JSON callback function ("instant" bookmarklets)
if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) {
$short = $return['shorturl'] ? $return['shorturl'] : '';
$message = "Short URL (Ctrl+C to copy)";
header('Content-type: application/json');
echo yourls_apply_filter( 'bookmarklet_jsonp', "yourls_callback({'short_url':'$short','message':'$message'});" );

die();
}
}

// Insert markup and all CSS & JS files
yourls_html_head();

// Display title
echo “

YOURLS – Your Own URL Shortener

n”;

// Display left hand menu
yourls_html_menu() ;

// Part to be executed if FORM has been submitted
if ( isset( $_REQUEST[‘url’] ) && $_REQUEST[‘url’] != ‘http://&#8217; ) {

// Display result message of short link creation
if( isset( $message ) ) {
echo “

$message

“;
}

// Include the Copy box and the Quick Share box
yourls_share_box( $url, $shorturl, $title, $text );

// Initialize clipboard — requires js/share.js and js/jquery.zclip.min.js to be properly loaded in the
echo <<<JS

init_clipboard();

JS;

// Part to be executed when no form has been submitted
} else {

$site = YOURLS_SITE;

// Display the form
echo <<<HTML

Enter a new URL to shorten

URL:

Optional custom short URL: $site/

Optional title:

HTML;

}

?>

Bookmarklets

Bookmark these links:

<a href="javascript:(function()%7Bvar%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:enc(s)),f='’,l=d.location,p=’?url=’+enc(l.href)+’&title=’+enc(d.title)+’&text=’+s2,u=f+p;try%7Bthrow(‘ozhismygod’);%7Dcatch(z)%7Ba=function()%7Bif(!w.open(u))l.href=u;%7D;if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();%7Dvoid(0);%7D)()” class=”bookmarklet”>Simple Shorten

<a href="javascript:(function()%7Bvar%20d=document,s=d.createElement('script');window.yourls_callback=function(r)%7Bif(r.short_url)%7Bprompt(r.message,r.short_url);%7Delse%7Balert('An%20error%20occured:%20'+r.message);%7D%7D;s.src='?url=’+encodeURIComponent(d.location.href)+’&jsonp=yourls’;void(d.body.appendChild(s));%7D)();” class=”bookmarklet”>Instant Shorten

<a href="javascript:(function()%7Bvar%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:enc(s)),f='’,l=d.location,k=prompt(%22Custom%20URL%22),k2=(k?’&keyword=’+k:%22%22),p=’?url=’+enc(l.href)+’&title=’+enc(d.title)+’&text=’+s2+k2,u=f+p;if(k!=null)%7Btry%7Bthrow(‘ozhismygod’);%7Dcatch(z)%7Ba=function()%7Bif(!w.open(u))l.href=u;%7D;if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();%7Dvoid(0)%7D%7D)()” class=”bookmarklet”>Custom Shorten

<a href="javascript:(function()%7Bvar%20d=document,k=prompt('Custom%20URL'),s=d.createElement('script');if(k!=null){window.yourls_callback=function(r)%7Bif(r.short_url)%7Bprompt(r.message,r.short_url);%7Delse%7Balert('An%20error%20occured:%20'+r.message);%7D%7D;s.src='?url=’+encodeURIComponent(d.location.href)+’&keyword=’+k+’&jsonp=yourls’;void(d.body.appendChild(s));%7D%7D)();” class=”bookmarklet”>Instant Custom Shorten

Please note

Be aware that a public interface will attract spammers. You are strongly advised to install anti spam plugins and any appropriate counter measure to deal with this issue.

<?php

// Display page footer
yourls_html_footer();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: