]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/functions-html.php
Filter and search URLs by date. Fixes issue 72.
[Github/YOURLS.git] / includes / functions-html.php
1 <?php\r
2 \r
3 // Display <h1> header and logo\r
4 function yourls_html_logo() {\r
5         ?>\r
6         <h1>\r
7                 <a href="<?php echo yourls_admin_url('index.php') ?>" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/>\r
8                 <img src="<?php echo YOURLS_SITE; ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" border="0" style="border: 0px;" /></a>\r
9         </h1>\r
10         <?php\r
11 }\r
12 \r
13 // Display HTML head and <body> tag\r
14 function yourls_html_head( $context = 'index' ) {\r
15         // All components to false, except when specified true\r
16         $share = $insert = $tablesorter = $tabs = $cal = false;\r
17         \r
18         // Load components as needed\r
19         switch ( $context ) {\r
20                 case 'infos':\r
21                         $share = $tabs = true;\r
22                         break;\r
23                         \r
24                 case 'bookmark':\r
25                         $share = $insert = $tablesorter = true;\r
26                         break;\r
27                         \r
28                 case 'index':\r
29                         $insert = $tablesorter = $cal = true;\r
30                         break;\r
31                 \r
32                 case 'install':\r
33                 case 'login':\r
34                 case 'new':\r
35                 case 'tools':\r
36                 case 'upgrade':\r
37                         break;\r
38         }\r
39         \r
40         // Force no cache for all admin pages\r
41         if( yourls_is_admin() && !headers_sent() ) {\r
42                 header( 'Expires: Thu, 23 Mar 1972 07:00:00 GMT' );\r
43                 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );\r
44                 header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );\r
45                 header( 'Pragma: no-cache' );\r
46         }\r
47         \r
48         ?>\r
49 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
50 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
51 <head>\r
52         <title>YOURLS &raquo; Your Own URL Shortener | <?php echo YOURLS_SITE; ?></title>\r
53         <link rel="icon" type="image/gif" href="<?php echo YOURLS_SITE; ?>/images/favicon.gif" />\r
54         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
55         <meta http-equiv="X-UA-Compatible" content="chrome=1" />\r
56         <meta name="copyright" content="Copyright &copy; 2008-<?php echo date('Y'); ?> YOURS" />\r
57         <meta name="author" content="Ozh Richard, Lester Chan" />\r
58         <meta name="description" content="Insert URL &laquo; YOURLS &raquo; Your Own URL Shortener' | <?php echo YOURLS_SITE; ?>" />\r
59         <script src="<?php echo YOURLS_SITE; ?>/js/jquery-1.3.2.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
60         <link rel="stylesheet" href="<?php echo YOURLS_SITE; ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
61         <?php if ($tabs) { ?>\r
62                 <link rel="stylesheet" href="<?php echo YOURLS_SITE; ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
63                 <script src="<?php echo YOURLS_SITE; ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
64         <?php } ?>\r
65         <?php if ($tablesorter) { ?>\r
66                 <link rel="stylesheet" href="<?php echo YOURLS_SITE; ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
67                 <script src="<?php echo YOURLS_SITE; ?>/js/jquery.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
68         <?php } ?>\r
69         <?php if ($insert) { ?>\r
70                 <script src="<?php echo YOURLS_SITE; ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
71         <?php } ?>\r
72         <?php if ($share) { ?>\r
73                 <link rel="stylesheet" href="<?php echo YOURLS_SITE; ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
74                 <script src="<?php echo YOURLS_SITE; ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
75         <?php } ?>\r
76         <?php if ($cal) { ?>\r
77                 <link rel="stylesheet" href="<?php echo YOURLS_SITE; ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
78                 <script src="<?php echo YOURLS_SITE; ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
79         <?php } ?>\r
80 </head>\r
81 <body class="<?php echo $context; ?>">\r
82 <div id="wrap">\r
83         <?php\r
84 }\r
85 \r
86 // Display HTML footer (including closing body & html tags)\r
87 function yourls_html_footer() {\r
88         global $ydb;\r
89         \r
90         $num_queries = $ydb->num_queries > 1 ? $ydb->num_queries.' queries' : $ydb->num_queries.' query';\r
91         ?>\r
92         </div> <?php // wrap ?>\r
93         <div id="footer"><p>Powered by <a href="http://yourls.org/" title="YOURLS">YOURLS</a> v<?php echo YOURLS_VERSION; echo ' &ndash; '.$num_queries; ?></p></div>\r
94         <?php if( defined('YOURLS_DEBUG') && YOURLS_DEBUG == true ) {\r
95                 echo '<p>'. $ydb->all_queries .'<p>';\r
96         } ?>\r
97         </body>\r
98         </html>\r
99         <?php\r
100 }\r
101 \r
102 // Display "Add new URL" box\r
103 function yourls_html_addnew( $url = '', $keyword = '' ) {\r
104         $url = $url ? $url : 'http://';\r
105         ?>\r
106         <div id="new_url">\r
107                 <div>\r
108                         <form id="new_url_form" action="" method="get">\r
109                                 <div><strong>Enter the URL</strong>:<input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" />\r
110                                 Optional: <strong>Custom short URL</strong>:<input type="text" id="add-keyword" name="keyword" value="<?php echo $keyword; ?>" class="text" size="8" />\r
111                                 <input type="button" id="add-button" name="add-button" value="Shorten The URL" class="button" onclick="add();" /></div>\r
112                         </form>\r
113                         <div id="feedback" style="display:none"></div>\r
114                 </div>\r
115         </div>\r
116         <?php\r
117 }\r
118 \r
119 // Display main table's footer\r
120 function yourls_html_tfooter( $params = array() ) {\r
121         extract( $params ); // extract $search_text, $page, $search_in_sql ...\r
122 \r
123         ?>\r
124         <tfoot>\r
125                 <tr>\r
126                         <th colspan="4" style="text-align: left;">\r
127                                 <form action="" method="get">\r
128                                         <div>\r
129                                                 Search&nbsp;for&nbsp;\r
130                                                 <input type="text" name="s_search" class="text" size="20" value="<?php echo $search_text; ?>" />\r
131                                                 &nbsp;in&nbsp;\r
132                                                 <select name="s_in" size="1">\r
133                                                         <option value="keyword"<?php if($search_in_sql == 'keyword') { echo ' selected="selected"'; } ?>>Short URL</option>\r
134                                                         <option value="url"<?php if($search_in_sql == 'url') { echo ' selected="selected"'; } ?>>URL</option>\r
135                                                         <option value="ip"<?php if($search_in_sql == 'ip') { echo ' selected="selected"'; } ?>>IP</option>\r
136                                                 </select>\r
137                                                 &ndash;&nbsp;Order&nbsp;by&nbsp;\r
138                                                 <select name="s_by" size="1">\r
139                                                         <option value="id"<?php if($sort_by_sql == 'keyword') { echo ' selected="selected"'; } ?>>Short URL</option>\r
140                                                         <option value="url"<?php if($sort_by_sql == 'url') { echo ' selected="selected"'; } ?>>URL</option>\r
141                                                         <option value="timestamp"<?php if($sort_by_sql == 'timestamp') { echo ' selected="selected"'; } ?>>Date</option>\r
142                                                         <option value="ip"<?php if($sort_by_sql == 'ip') { echo ' selected="selected"'; } ?>>IP</option>\r
143                                                         <option value="clicks"<?php if($sort_by_sql == 'clicks') { echo ' selected="selected"'; } ?>>Clicks</option>\r
144                                                 </select>\r
145                                                 <select name="s_order" size="1">\r
146                                                         <option value="asc"<?php if($sort_order_sql == 'asc') { echo ' selected="selected"'; } ?>>Ascending</option>\r
147                                                         <option value="desc"<?php if($sort_order_sql == 'desc') { echo ' selected="selected"'; } ?>>Descending</option>\r
148                                                 </select>\r
149                                                 &ndash;&nbsp;Show&nbsp;\r
150                                                 <input type="text" name="perpage" class="text" size="2" value="<?php echo $perpage; ?>" />&nbsp;rows<br/>\r
151                                                 \r
152                                                 Show links with\r
153                                                 <select name="link_filter" size="1">\r
154                                                         <option value="more"<?php if($link_filter === 'more') { echo ' selected="selected"'; } ?>>more</option>\r
155                                                         <option value="less"<?php if($link_filter === 'less') { echo ' selected="selected"'; } ?>>less</option>\r
156                                                 </select>\r
157                                                 than\r
158                                                 <input type="text" name="link_limit" class="text" size="4" value="<?php echo $link_limit; ?>" />clicks<br/>\r
159                                                 \r
160                                                 Show links created\r
161                                                 <select name="date_filter" id="date_filter" size="1">\r
162                                                         <option value="before"<?php if($date_filter === 'before') { echo ' selected="selected"'; } ?>>before</option>\r
163                                                         <option value="after"<?php if($date_filter === 'after') { echo ' selected="selected"'; } ?>>after</option>\r
164                                                         <option value="between"<?php if($date_filter === 'between') { echo ' selected="selected"'; } ?>> between</option>\r
165                                                 </select>\r
166                                                 <input type="text" name="date_first" id="date_first" class="text" size="12" value="<?php echo $date_first; ?>" />\r
167                                                 <span id="date_and" <?php if($date_filter === 'between') { echo ' style="display:inline"'; } ?>> and </span>\r
168                                                 <input type="text" name="date_second" id="date_second" class="text" size="12" value="<?php echo $date_second; ?>" <?php if($date_filter === 'between') { echo ' style="display:inline"'; } ?>/>\r
169                                                 \r
170                                                 <div style="float:right;">\r
171                                                         <input type="submit" id="submit-sort" value="Filter" class="button primary" />\r
172                                                         &nbsp;\r
173                                                         <input type="button" id="submit-clear-filter" value="Clear Filter" class="button" onclick="window.parent.location.href = 'index.php'" />\r
174                                                 </div>\r
175 \r
176                                                 \r
177                                         </div>\r
178                                 </form>\r
179                         </th>\r
180                         <th colspan="3" style="text-align: right;">\r
181                                 Pages (<?php echo $total_pages; ?>):\r
182                                 <?php\r
183                                         if ($page >= 4) {\r
184                                                 echo '<b><a href="'.$base_page.'?s_by='.$sort_by_sql.'&amp;s_order='.$sort_order_sql.$search_url.'&amp;perpage='.$perpage.'&amp;page=1'.'" title="Go to First Page">&laquo; First</a></b> ... ';\r
185                                         }\r
186                                         if($page > 1) {\r
187                                                 echo ' <b><a href="'.$base_page.'?s_by='.$sort_by_sql.'&amp;s_order='.$sort_order_sql.$search_url.'&amp;perpage='.$perpage.'&amp;page='.($page-1).'" title="&laquo; Go to Page '.($page-1).'">&laquo;</a></b> ';\r
188                                         }\r
189                                         for($i = $page - 2 ; $i  <= $page +2; $i++) {\r
190                                                 if ($i >= 1 && $i <= $total_pages) {\r
191                                                         if($i == $page) {\r
192                                                                 echo "<strong>[$i]</strong> ";\r
193                                                         } else {\r
194                                                                 echo '<a href="'.$base_page.'?s_by='.$sort_by_sql.'&amp;s_order='.$sort_order_sql.$search_url.'&amp;perpage='.$perpage.'&amp;page='.($i).'" title="Page '.$i.'">'.$i.'</a> ';\r
195                                                         }\r
196                                                 }\r
197                                         }\r
198                                         if($page < $total_pages) {\r
199                                                 echo ' <b><a href="'.$base_page.'?s_by='.$sort_by_sql.'&amp;s_order='.$sort_order_sql.$search_url.'&amp;perpage='.$perpage.'&amp;page='.($page+1).'" title="Go to Page '.($page+1).' &raquo;">&raquo;</a></b> ';\r
200                                         }\r
201                                         if (($page+2) < $total_pages) {\r
202                                                 echo ' ... <b><a href="'.$base_page.'?s_by='.$sort_by_sql.'&amp;s_order='.$sort_order_sql.$search_url.'&amp;perpage='.$perpage.'&amp;page='.($total_pages).'" title="Go to Last Page">Last &raquo;</a></b>';\r
203                                         }\r
204                                 ?>\r
205                         </th>\r
206                 </tr>\r
207         </tfoot>\r
208         <?php\r
209 }\r
210 \r
211 // Display the Quick Share box of the tools.php page\r
212 function yourls_share_box( $longurl, $shorturl, $title='', $text='', $shortlink_title = '<h2>Your short link</h2>', $share_title = '<h2>Quick Share</h2>' ) {\r
213         $text = ( $text ? '"'.$text.'" ' : '' );\r
214         $title = ( $title ? "$title " : '' );\r
215         $share = htmlspecialchars_decode( $title.$text.$shorturl );\r
216         $_share = rawurlencode( $share );\r
217         $_url = rawurlencode( $shorturl );\r
218         $count = 140 - strlen( $share );\r
219         ?>\r
220         \r
221         <div id="shareboxes">\r
222 \r
223                 <div id="copybox" class="share">\r
224                 <?php echo $shortlink_title; ?>\r
225                         <p><input id="copylink" class="text" size="40" value="<?php echo $shorturl; ?>" /></p>\r
226                         <p><small>Original link: <a href="<?php echo $longurl; ?>"><?php echo $longurl; ?></a></small></p>\r
227                 </div>\r
228 \r
229                 <div id="sharebox" class="share">\r
230                         <?php echo $share_title; ?>\r
231                         <div id="tweet">\r
232                                 <span id="charcount"><?php echo $count; ?></span>\r
233                                 <textarea id="tweet_body"><?php echo $share; ?></textarea>\r
234                         </div>\r
235                         <p id="share_links">Share with \r
236                                 <a id="share_tw" href="http://twitter.com/home?status=<?php echo $_share; ?>" title="Tweet this!" onclick="share('tw');return false">Twitter</a>\r
237                                 <a id="share_fb" href="http://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="Share on Facebook" onclick="share('fb');return false;">Facebook</a>\r
238                                 <a id="share_ff" href="http://friendfeed.com/share/bookmarklet/frame#title=<?php echo $_share; ?>" title="Share on Friendfeed" onclick="javascript:share('ff');return false;">FriendFeed</a>\r
239                         </p>\r
240                 </div>\r
241         \r
242         </div>\r
243         \r
244         <?php\r
245 }\r
246 \r
247 // Die die die\r
248 function yourls_die( $message = '', $title = '', $header_code = 200 ) {\r
249         yourls_status_header( $header_code );\r
250         \r
251         yourls_html_head();\r
252         yourls_html_logo();\r
253         echo "<h2>$title</h2>";\r
254         echo "<p>$message</p>";\r
255         yourls_html_footer();\r
256         die();\r
257 }\r
258 \r
259 // Echo HTML tag for a link\r
260 function yourls_html_link( $href, $title = '', $element = '' ) {\r
261         if( !$title )\r
262                 $title = $href;\r
263         if( $element )\r
264                 $element = "id='$element'";\r
265         echo "<a href='$href' $element>$title</a>";\r
266 }\r
267 \r
268 // Display the login screen. Nothing past this point.\r
269 function yourls_login_screen( $error_msg = '' ) {\r
270         yourls_html_head( 'login' );\r
271         \r
272         $action = ( isset($_GET['mode']) && $_GET['mode'] == 'logout' ? '?' : '' );\r
273 \r
274         yourls_html_logo();\r
275         ?>\r
276         <div id="login">\r
277                 <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>\r
278                         <?php\r
279                                 if(!empty($error_msg)) {\r
280                                         echo '<p class="error">'.$error_msg.'</p>';\r
281                                 }\r
282                         ?>\r
283                         <p>\r
284                                 <label for="username">Username</label><br />\r
285                                 <input type="text" id="username" name="username" size="30" class="text" />\r
286                         </p>\r
287                         <p>\r
288                                 <label for="password">Password</label><br />\r
289                                 <input type="password" id="password" name="password" size="30" class="text" />\r
290                         </p>\r
291                         <p style="text-align: right;">\r
292                                 <input type="submit" id="submit" name="submit" value="Login" class="button" />\r
293                         </p>\r
294                 </form>\r
295                 <script type="text/javascript">$('#username').focus();</script>\r
296         </div>\r
297         <?php\r
298         yourls_html_footer();\r
299         die();\r
300 }\r
301 \r
302 // Display the admin menu\r
303 function yourls_html_menu() {\r
304         ?>\r
305         <ul id="admin_menu">\r
306         <?php if ( yourls_is_private() ) { ?>\r
307                 <li>Hello <strong><?php echo YOURLS_USER; ?></strong> (<a href="?mode=logout" title="Logout">Logout</a>)</li>\r
308         <?php } ?>\r
309                 <li>Go to the <a href="<?php echo yourls_admin_url('index.php') ?>">Admin Interface</a></li>\r
310                 <li>Check the <a href="<?php echo yourls_admin_url('tools.php'); ?>">Tools</a></li>\r
311                 <li>Read the <a href="<?php echo YOURLS_SITE; ?>/readme.html">Help</a></li>\r
312         </ul>\r
313         <?php\r
314 }\r