]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - sample-public-front-page.php
Tip on how to add the Quick Share box to the public page. See issue 33.
[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/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 If you want to add the Quick Share box like on the private bookmarklet, simply use this PHP function:\r
41 <?php yourls_share_box( $url, $shorturl ); ?>\r
42 For all the special stuff to work you need to include js/share.js in the <head> of your page\r
43 */\r
44 \r
45 \r
46 // Part to be executed when no form has been submitted\r
47 } else {\r
48 \r
49         echo <<<HTML\r
50         <h2>Enter a new URL to shorten</h2>\r
51         <form method="post" action="">\r
52         <p><label>URL: <input type="text" name="url" value="http://" size="50" /></label></p>\r
53         <p><label>Optional custom keyword: <input type="text" name="keyword" size="5" /></label></p>\r
54         <p><input type="submit" value="Shorten" /></p>\r
55         </form> \r
56 HTML;\r
57 \r
58 }\r
59 \r
60 ?>\r
61 \r
62 <!-- Example bookmarklet. Be sure to rename the link target from "sample-public-front-page.php" to whatever you'll use (probably index.php) -->\r
63 <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
64 \r
65 <div id="footer"><p>Powered by <a href="http://yourls.org/" title="YOURLS">YOURLS</a> v<?php echo YOURLS_VERSION; ?></p></div>\r
66 </body>\r
67 </html>