]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - public-sample.php
1.3 RC1 massive commit
[Github/YOURLS.git] / public-sample.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/config.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         $db = yourls_db_connect();\r
26 \r
27         $return = yourls_add_new_link( $url, $keyword, $db );\r
28         \r
29         $shorturl = $return['shorturl'];\r
30         $message = $return['message'];\r
31         \r
32         echo <<<RESULT\r
33         <h2>URL has been shortened</h2>\r
34         <p>Original URL: <code><a href="$url">$url</a></code></p>\r
35         <p>Short URL: <code><a href="$shorturl">$shorturl</a></code></p>\r
36         <p>$message</p>\r
37 RESULT;\r
38 \r
39 \r
40 // Part to be executed when no form has been submitted\r
41 } else {\r
42 \r
43         echo <<<HTML\r
44         <h2>Enter a new URL to shorten</h2>\r
45         <form method="post" action="">\r
46         <p><label>URL: <input type="text" name="url" value="http://" size="50" /></label></p>\r
47         <p><label>Optional custom keyword: <input type="text" name="keyword" size="5" /></label></p>\r
48         <p><input type="submit" value="Shorten" /></p>\r
49         </form> \r
50 HTML;\r
51 \r
52 }\r
53 \r
54 ?>\r
55 \r
56 <div id="footer"><p>Powered by <a href="http://yourls.org/" title="YOURLS">YOURLS</a> v<?php echo YOURLS_VERSION; ?></p></div>\r
57 </body>\r
58 </html>