]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - sample-public-front-page.php
Logic change: include "load-yourls.php" instead of "config.php" to start engine
[Github/YOURLS.git] / sample-public-front-page.php
1 <html>\r
2 <head>\r
3 <title>YOURLS Public Interface Sample</title>\r
4 <style>\r
5 body {background:#BFE0FE; color:#666; font:16px/30px verdana,arial,sans-serif;}\r
6 h1 {text-align:center}\r
7 h2 {border-bottom:1px solid white}\r
8 #credits, #credit a {font-size:80%; color:#aaa}\r
9 </style>\r
10 <!-- customize more: CSS, etc -->\r
11 </head>\r
12 \r
13 <body>\r
14 <h1>YOURLS: Your Own URL Shortener</h1>\r
15 \r
16 <?php\r
17 require_once( dirname(__FILE__).'/includes/load-yourls.php' );\r
18 \r
19 // Part to be executed if FORM has been submitted\r
20 if ( isset($_REQUEST['url']) ) {\r
21 \r
22         $url = $_REQUEST['url'];\r
23         $keyword = isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ;\r
24 \r
25         $return = yourls_add_new_link( $url, $keyword );\r
26         \r
27         $shorturl = $return['shorturl'];\r
28         $message = $return['message'];\r
29         \r
30         echo <<<RESULT\r
31         <h2>URL has been shortened</h2>\r
32         <p>Original URL: <code><a href="$url">$url</a></code></p>\r
33         <p>Short URL: <code><a href="$shorturl">$shorturl</a></code></p>\r
34         <p>$message</p>\r
35 RESULT;\r
36 \r
37 /*\r
38 If you want to add the Quick Share box like on the private bookmarklet, simply use this PHP function:\r
39 <?php yourls_share_box( $url, $shorturl ); ?>\r
40 For all the special stuff to work you need to include js/share.js in the <head> of your page\r
41 */\r
42 \r
43 \r
44 // Part to be executed when no form has been submitted\r
45 } else {\r
46 \r
47         echo <<<HTML\r
48         <h2>Enter a new URL to shorten</h2>\r
49         <form method="post" action="">\r
50         <p><label>URL: <input type="text" name="url" value="http://" size="50" /></label></p>\r
51         <p><label>Optional custom keyword: <input type="text" name="keyword" size="5" /></label></p>\r
52         <p><input type="submit" value="Shorten" /></p>\r
53         </form> \r
54 HTML;\r
55 \r
56 }\r
57 \r
58 ?>\r
59 \r
60 <!-- Example bookmarklet. Be sure to rename the link target from "sample-public-front-page.php" to whatever you'll use (probably index.php) -->\r
61 <p><a href="javascript:void(location.href='<?php echo YOURLS_SITE; ?>/sample-public-front-page.php?format=simple&action=shorturl&url='+escape(location.href))">bookmarklet</a>\r
62 \r
63 <div id="footer"><p>Powered by <a href="http://yourls.org/" title="YOURLS">YOURLS</a> v<?php echo YOURLS_VERSION; ?></p></div>\r
64 </body>\r
65 </html>