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