[ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This is an example file for a public interface and a bookmarklet. It 5 * is provided so you can build from it and customize to suit your needs. 6 * It's not really part of the project. Don't submit feature requests 7 * about this file. It's _your_ job to make it what you need it to be :) 8 * 9 * Rename to .php 10 * 11 */ 12 13 // Start YOURLS engine 14 require_once( dirname(__FILE__).'/includes/load-yourls.php' ); 15 16 // Change this to match the URL of your public interface. Something like: http://your-own-domain-here.com/index.php 17 $page = YOURLS_SITE . '/sample-public-front-page.php' ; 18 19 // Part to be executed if FORM has been submitted 20 if ( isset( $_REQUEST['url'] ) && $_REQUEST['url'] != 'http://' ) { 21 22 // Get parameters -- they will all be sanitized in yourls_add_new_link() 23 $url = $_REQUEST['url']; 24 $keyword = isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ; 25 $title = isset( $_REQUEST['title'] ) ? $_REQUEST['title'] : '' ; 26 $text = isset( $_REQUEST['text'] ) ? $_REQUEST['text'] : '' ; 27 28 // Create short URL, receive array $return with various information 29 $return = yourls_add_new_link( $url, $keyword, $title ); 30 31 $shorturl = isset( $return['shorturl'] ) ? $return['shorturl'] : ''; 32 $message = isset( $return['message'] ) ? $return['message'] : ''; 33 $title = isset( $return['title'] ) ? $return['title'] : ''; 34 $status = isset( $return['status'] ) ? $return['status'] : ''; 35 36 // Stop here if bookmarklet with a JSON callback function ("instant" bookmarklets) 37 if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) { 38 $short = $return['shorturl'] ? $return['shorturl'] : ''; 39 $message = "Short URL (Ctrl+C to copy)"; 40 header('Content-type: application/json'); 41 echo yourls_apply_filter( 'bookmarklet_jsonp', "yourls_callback({'short_url':'$short','message':'$message'});" ); 42 43 die(); 44 } 45 } 46 47 // Insert <head> markup and all CSS & JS files 48 yourls_html_head(); 49 50 // Display title 51 echo "<h1>YOURLS - Your Own URL Shortener</h1>\n"; 52 53 // Display left hand menu 54 yourls_html_menu() ; 55 56 // Part to be executed if FORM has been submitted 57 if ( isset( $_REQUEST['url'] ) && $_REQUEST['url'] != 'http://' ) { 58 59 // Display result message of short link creation 60 if( isset( $message ) ) { 61 echo "<h2>$message</h2>"; 62 } 63 64 if( $status == 'success' ) { 65 // Include the Copy box and the Quick Share box 66 yourls_share_box( $url, $shorturl, $title, $text ); 67 68 // Initialize clipboard -- requires js/share.js and js/clipboard.min.js to be properly loaded in the <head> 69 echo "<script>init_clipboard();</script>\n"; 70 } 71 72 // Part to be executed when no form has been submitted 73 } else { 74 75 $site = YOURLS_SITE; 76 77 // Display the form 78 echo <<<HTML 79 <h2>Enter a new URL to shorten</h2> 80 <form method="post" action=""> 81 <p><label>URL: <input type="text" class="text" name="url" value="http://" /></label></p> 82 <p><label>Optional custom short URL: $site/<input type="text" class="text" name="keyword" /></label></p> 83 <p><label>Optional title: <input type="text" class="text" name="title" /></label></p> 84 <p><input type="submit" class="button primary" value="Shorten" /></p> 85 </form> 86 HTML; 87 88 } 89 90 ?> 91 92 <h2>Bookmarklets</h2> 93 94 <p>Bookmark these links:</p> 95 96 <p> 97 98 <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='<?php echo $page; ?>',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">Default</a> 99 100 <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='<?php echo $page; ?>',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</a> 101 102 <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%20occurred:%20'+r.message);%7D%7D;s.src='<?php echo $page; ?>?url='+encodeURIComponent(d.location.href)+'&jsonp=yourls';void(d.body.appendChild(s));%7D)();" class="bookmarklet">Popup</a> 103 104 <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%20occurred:%20'+r.message);%7D%7D;s.src='<?php echo $page; ?>?url='+encodeURIComponent(d.location.href)+'&keyword='+k+'&jsonp=yourls';void(d.body.appendChild(s));%7D%7D)();" class="bookmarklet">Custom Popup</a> 105 106 </p> 107 108 <h2>Please note</h2> 109 110 <p>Be aware that a public interface <strong>will</strong> attract spammers. You are strongly advised to install anti spam plugins and any appropriate counter measure to deal with this issue.</p> 111 112 <?php 113 114 // Display page footer 115 yourls_html_footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 21 05:10:11 2025 | Cross-referenced by PHPXref 0.7.1 |