]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/functions-html.php
Allow different styles of notice boxes. Fixes issue 1218.
[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         yourls_do_action( 'pre_html_logo' );\r
6         ?>\r
7         <h1>\r
8                 <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
9                 <img src="<?php yourls_site_url(); ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" border="0" style="border: 0px;" /></a>\r
10         </h1>\r
11         <?php\r
12         yourls_do_action( 'html_logo' );\r
13 }\r
14 \r
15 // Display HTML head and <body> tag\r
16 function yourls_html_head( $context = 'index', $title = '' ) {\r
17 \r
18         yourls_do_action( 'pre_html_head', $context, $title );\r
19         \r
20         // All components to false, except when specified true\r
21         $share = $insert = $tablesorter = $tabs = $cal = $charts = false;\r
22         \r
23         // Load components as needed\r
24         switch ( $context ) {\r
25                 case 'infos':\r
26                         $share = $tabs = $charts = true;\r
27                         break;\r
28                         \r
29                 case 'bookmark':\r
30                         $share = $insert = $tablesorter = true;\r
31                         break;\r
32                         \r
33                 case 'index':\r
34                         $insert = $tablesorter = $cal = $share = true;\r
35                         break;\r
36                         \r
37                 case 'plugins':\r
38                 case 'tools':\r
39                         $tablesorter = true;\r
40                         break;\r
41                 \r
42                 case 'install':\r
43                 case 'login':\r
44                 case 'new':\r
45                 case 'upgrade':\r
46                         break;\r
47         }\r
48         \r
49         // Force no cache for all admin pages\r
50         if( yourls_is_admin() && !headers_sent() ) {\r
51                 header( 'Expires: Thu, 23 Mar 1972 07:00:00 GMT' );\r
52                 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );\r
53                 header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );\r
54                 header( 'Pragma: no-cache' );\r
55                 yourls_do_action( 'admin_headers', $context, $title );\r
56         }\r
57         \r
58         // Store page context in global object\r
59         global $ydb;\r
60         $ydb->context = $context;\r
61         \r
62         // Body class\r
63         $bodyclass = yourls_apply_filter( 'bodyclass', '' );\r
64         $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' );\r
65         \r
66         // Page title\r
67         $_title = 'YOURLS &mdash; Your Own URL Shortener | ' . yourls_link();\r
68         $title = $title ? $title . " &laquo; " . $_title : $_title;\r
69         $title = yourls_apply_filter( 'html_title', $title, $context );\r
70         \r
71         ?>\r
72 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
73 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
74 <head>\r
75         <title><?php echo $title ?></title>\r
76         <link rel="shortcut icon" href="<?php yourls_favicon(); ?>" />\r
77         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
78         <meta http-equiv="X-UA-Compatible" content="chrome=1" />\r
79         <meta name="author" content="Ozh RICHARD & Lester CHAN for http://yourls.org/" />\r
80         <meta name="generator" content="YOURLS <?php echo YOURLS_VERSION ?>" />\r
81         <meta name="description" content="Insert URL &laquo; YOURLS &raquo; Your Own URL Shortener' | <?php yourls_site_url(); ?>" />\r
82         <script src="<?php yourls_site_url(); ?>/js/jquery-1.8.2.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
83         <script src="<?php yourls_site_url(); ?>/js/common.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
84         <script src="<?php yourls_site_url(); ?>/js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
85         <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
86         <?php if ( $tabs ) { ?>\r
87                 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
88                 <script src="<?php yourls_site_url(); ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
89         <?php } ?>\r
90         <?php if ( $tablesorter ) { ?>\r
91                 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
92                 <script src="<?php yourls_site_url(); ?>/js/jquery.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
93         <?php } ?>\r
94         <?php if ( $insert ) { ?>\r
95                 <script src="<?php yourls_site_url(); ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
96         <?php } ?>\r
97         <?php if ( $share ) { ?>\r
98                 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
99                 <script src="<?php yourls_site_url(); ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
100                 <script src="<?php yourls_site_url(); ?>/js/jquery.zclip.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
101         <?php } ?>\r
102         <?php if ( $cal ) { ?>\r
103                 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />\r
104                 <script src="<?php yourls_site_url(); ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>\r
105         <?php } ?>\r
106         <?php if ( $charts ) { ?>\r
107                 <script type="text/javascript" src="https://www.google.com/jsapi"></script>\r
108                 <script type="text/javascript">\r
109                          google.load('visualization', '1.0', {'packages':['corechart', 'geochart']});
110                 </script>\r
111         <?php } ?>\r
112         <script type="text/javascript">\r
113         //<![CDATA[\r
114                 var ajaxurl  = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';\r
115                 var zclipurl = '<?php yourls_site_url(); ?>/js/ZeroClipboard.swf';\r
116         //]]>\r
117         </script>\r
118         <?php yourls_do_action( 'html_head', $context ); ?>\r
119 </head>\r
120 <body class="<?php echo $context; ?> <?php echo $bodyclass; ?>">\r
121 <div id="wrap">\r
122         <?php\r
123 }\r
124 \r
125 // Display HTML footer (including closing body & html tags)\r
126 function yourls_html_footer() {\r
127         global $ydb;\r
128         \r
129         $num_queries = $ydb->num_queries > 1 ? $ydb->num_queries.' queries' : $ydb->num_queries.' query';\r
130         ?>\r
131         </div> <?php // wrap ?>\r
132         <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
133         <?php if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) {\r
134                 echo '<p>'. $ydb->all_queries .'<p>';\r
135         } ?>\r
136         <?php yourls_do_action( 'html_footer', $ydb->context ); ?>\r
137         </body>\r
138         </html>\r
139         <?php\r
140 }\r
141 \r
142 // Display "Add new URL" box\r
143 function yourls_html_addnew( $url = '', $keyword = '' ) {\r
144         $url = $url ? $url : 'http://';\r
145         ?>\r
146         <div id="new_url">\r
147                 <div>\r
148                         <form id="new_url_form" action="" method="get">\r
149                                 <div><strong>Enter the URL</strong>:<input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" />\r
150                                 Optional: <strong>Custom short URL</strong>:<input type="text" id="add-keyword" name="keyword" value="<?php echo $keyword; ?>" class="text" size="8" />\r
151                                 <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?>\r
152                                 <input type="button" id="add-button" name="add-button" value="Shorten The URL" class="button" onclick="add();" /></div>\r
153                         </form>\r
154                         <div id="feedback" style="display:none"></div>\r
155                 </div>\r
156                 <?php yourls_do_action( 'html_addnew' ); ?>\r
157         </div>\r
158         <?php \r
159 }\r
160 \r
161 // Display main table's footer\r
162 function yourls_html_tfooter( $params = array() ) {\r
163         extract( $params ); // extract $search_text, $page, $search_in_sql ...\r
164 \r
165         ?>\r
166         <tfoot>\r
167                 <tr>\r
168                         <th colspan="6">\r
169                         <div id="filter_form">\r
170                                 <form action="" method="get">\r
171                                         <div id="filter_options">\r
172                                                 Search&nbsp;for&nbsp;\r
173                                                 <input type="text" name="s_search" class="text" size="12" value="<?php echo $search_text; ?>" />\r
174                                                 &nbsp;in&nbsp;\r
175                                                 <select name="s_in" size="1">\r
176                                                         <option value="keyword"<?php if($search_in_sql == 'keyword') { echo ' selected="selected"'; } ?>>Short URL</option>\r
177                                                         <option value="url"<?php if($search_in_sql == 'url') { echo ' selected="selected"'; } ?>>URL</option>\r
178                                                         <option value="title"<?php if($search_in_sql == 'title') { echo ' selected="selected"'; } ?>>Title</option>\r
179                                                         <option value="ip"<?php if($search_in_sql == 'ip') { echo ' selected="selected"'; } ?>>IP</option>\r
180                                                 </select>\r
181                                                 &ndash;&nbsp;Order&nbsp;by&nbsp;\r
182                                                 <select name="s_by" size="1">\r
183                                                         <option value="id"<?php if($sort_by_sql == 'keyword') { echo ' selected="selected"'; } ?>>Short URL</option>\r
184                                                         <option value="url"<?php if($sort_by_sql == 'url') { echo ' selected="selected"'; } ?>>URL</option>\r
185                                                         <option value="timestamp"<?php if($sort_by_sql == 'timestamp') { echo ' selected="selected"'; } ?>>Date</option>\r
186                                                         <option value="ip"<?php if($sort_by_sql == 'ip') { echo ' selected="selected"'; } ?>>IP</option>\r
187                                                         <option value="clicks"<?php if($sort_by_sql == 'clicks') { echo ' selected="selected"'; } ?>>Clicks</option>\r
188                                                 </select>\r
189                                                 <select name="s_order" size="1">\r
190                                                         <option value="asc"<?php if($sort_order_sql == 'asc') { echo ' selected="selected"'; } ?>>Ascending</option>\r
191                                                         <option value="desc"<?php if($sort_order_sql == 'desc') { echo ' selected="selected"'; } ?>>Descending</option>\r
192                                                 </select>\r
193                                                 &ndash;&nbsp;Show&nbsp;\r
194                                                 <input type="text" name="perpage" class="text" size="2" value="<?php echo $perpage; ?>" />&nbsp;rows<br/>\r
195                                                 \r
196                                                 Show links with\r
197                                                 <select name="link_filter" size="1">\r
198                                                         <option value="more"<?php if($link_filter === 'more') { echo ' selected="selected"'; } ?>>more</option>\r
199                                                         <option value="less"<?php if($link_filter === 'less') { echo ' selected="selected"'; } ?>>less</option>\r
200                                                 </select>\r
201                                                 than\r
202                                                 <input type="text" name="link_limit" class="text" size="4" value="<?php echo $link_limit; ?>" />clicks<br/>\r
203                                                 \r
204                                                 Show links created\r
205                                                 <select name="date_filter" id="date_filter" size="1">\r
206                                                         <option value="before"<?php if($date_filter === 'before') { echo ' selected="selected"'; } ?>>before</option>\r
207                                                         <option value="after"<?php if($date_filter === 'after') { echo ' selected="selected"'; } ?>>after</option>\r
208                                                         <option value="between"<?php if($date_filter === 'between') { echo ' selected="selected"'; } ?>> between</option>\r
209                                                 </select>\r
210                                                 <input type="text" name="date_first" id="date_first" class="text" size="12" value="<?php echo $date_first; ?>" />\r
211                                                 <span id="date_and" <?php if($date_filter === 'between') { echo ' style="display:inline"'; } ?>> and </span>\r
212                                                 <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
213                                                 \r
214                                                 <div id="filter_buttons">\r
215                                                         <input type="submit" id="submit-sort" value="Search" class="button primary" />\r
216                                                         &nbsp;\r
217                                                         <input type="button" id="submit-clear-filter" value="Clear" class="button" onclick="window.parent.location.href = 'index.php'" />\r
218                                                 </div>\r
219                                 \r
220                                         </div>\r
221                                 </form>\r
222                         </div>\r
223                         <div id="pagination">\r
224                                 <span class="navigation">\r
225                                 <?php if( $total_pages > 1 ) { ?>\r
226                                         <span class="nav_total"><?php echo $total_pages .' '. yourls_plural( 'page', $total_pages ); ?></span>\r
227                                         <?php\r
228                                         $base_page = yourls_admin_url( 'index.php' );\r
229                                         // Pagination offsets: min( max ( zomg! ) );\r
230                                         $p_start = max(  min( $total_pages - 4, $page - 2 ), 1 );\r
231                                         $p_end = min( max( 5, $page + 2 ), $total_pages );\r
232                                         if( $p_start >= 2 ) {\r
233                                                 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page );\r
234                                                 echo '<span class="nav_link nav_first"><a href="' . $link . '" title="Go to First Page">&laquo; First</a></span>';\r
235                                                 echo '<span class="nav_link nav_prev"></span>';\r
236                                         }\r
237                                         for( $i = $p_start ; $i <= $p_end; $i++ ) {\r
238                                                 if( $i == $page ) {\r
239                                                         echo "<span class='nav_link nav_current'>$i</span>";\r
240                                                 } else {\r
241                                                         $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page );\r
242                                                         echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="Page '.$i.'">'.$i.'</a></span>';\r
243                                                 }\r
244                                         }\r
245                                         if( ( $p_end ) < $total_pages ) {\r
246                                                 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page );\r
247                                                 echo '<span class="nav_link nav_next"></span>';\r
248                                                 echo '<span class="nav_link nav_last"><a href="' . $link . '" title="Go to Last Page">Last &raquo;</a></span>';\r
249                                         }\r
250                                         ?>\r
251                                 <?php } ?>\r
252                                 </span>\r
253                         </div>\r
254                         </th>\r
255                 </tr>\r
256                 <?php yourls_do_action( 'html_tfooter' ); ?>\r
257         </tfoot>\r
258         <?php\r
259 }\r
260 \r
261 // Display the Quick Share box\r
262 function yourls_share_box( $longurl, $shorturl, $title='', $text='', $shortlink_title = '<h2>Your short link</h2>', $share_title = '<h2>Quick Share</h2>', $hidden = false ) {\r
263         // Allow plugins to short-circuit the whole function\r
264         $pre = yourls_apply_filter( 'shunt_share_box', false );\r
265         if ( false !== $pre )\r
266                 return $pre;\r
267                 \r
268         $text = ( $text ? '"'.$text.'" ' : '' );\r
269         $title = ( $title ? "$title " : '' );\r
270         $share = htmlspecialchars_decode( $title.$text.$shorturl );\r
271         $count = 140 - strlen( $share );\r
272         $hidden = ( $hidden ? 'style="display:none;"' : '' );\r
273         \r
274         // Allow plugins to filter all data\r
275         $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );\r
276         $data = yourls_apply_filter( 'share_box_data', $data );\r
277         extract( $data );\r
278         \r
279         $_share = rawurlencode( $share );\r
280         $_url = rawurlencode( $shorturl );\r
281         ?>\r
282         \r
283         <div id="shareboxes" <?php echo $hidden; ?>>\r
284 \r
285                 <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>\r
286 \r
287                 <div id="copybox" class="share">\r
288                 <?php echo $shortlink_title; ?>\r
289                         <p><input id="copylink" class="text" size="32" value="<?php echo $shorturl; ?>" /></p>\r
290                         <p><small>Long link: <a id="origlink" href="<?php echo $longurl; ?>"><?php echo $longurl; ?></a></small>\r
291                         <?php if( yourls_do_log_redirect() ) { ?>\r
292                         <br/><small>Stats: <a id="statlink" href="<?php echo $shorturl; ?>+"><?php echo $shorturl; ?>+</a></small>\r
293                         <input type="hidden" id="titlelink" value="<?php echo $title; ?>" />\r
294                         <?php } ?>\r
295                         </p>\r
296                 </div>\r
297 \r
298                 <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>\r
299 \r
300                 <div id="sharebox" class="share">\r
301                         <?php echo $share_title; ?>\r
302                         <div id="tweet">\r
303                                 <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>\r
304                                 <textarea id="tweet_body"><?php echo $share; ?></textarea>\r
305                         </div>\r
306                         <p id="share_links">Share with \r
307                                 <a id="share_tw" href="http://twitter.com/home?status=<?php echo $_share; ?>" title="Tweet this!" onclick="share('tw');return false">Twitter</a>\r
308                                 <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
309                                 <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
310                                 <?php\r
311                                 yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );\r
312                                 // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.\r
313                                 ?>\r
314                         </p>\r
315                 </div>\r
316                 \r
317                 <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>\r
318         \r
319         </div>\r
320         \r
321         <?php\r
322 }\r
323 \r
324 // Die die die\r
325 function yourls_die( $message = '', $title = '', $header_code = 200 ) {\r
326         yourls_status_header( $header_code );\r
327         \r
328         if( !yourls_did_action( 'html_head' ) ) {\r
329                 yourls_html_head();\r
330                 yourls_html_logo();\r
331         }\r
332         echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" );\r
333         echo yourls_apply_filter( 'die_message', "<p>$message</p>" );\r
334         yourls_do_action( 'yourls_die' );\r
335         if( !yourls_did_action( 'html_head' ) ) {\r
336                 yourls_html_footer();\r
337         }\r
338         die();\r
339 }\r
340 \r
341 // Add the "Edit" row\r
342 function yourls_table_edit_row( $keyword ) {\r
343         global $ydb;\r
344         \r
345         $table = YOURLS_DB_TABLE_URL;\r
346         $keyword = yourls_sanitize_string( $keyword );\r
347         $id = yourls_string2htmlid( $keyword ); // used as HTML #id\r
348         $url = yourls_get_keyword_longurl( $keyword );\r
349         $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );\r
350         $safe_url = stripslashes( $url );\r
351         $safe_title = stripslashes( $title );\r
352         $www = yourls_link();\r
353         \r
354         $save_link = yourls_nonce_url( 'save-link_'.$id,\r
355                 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit_save', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) \r
356         );\r
357         \r
358         $nonce = yourls_create_nonce( 'edit-save_'.$id );\r
359         \r
360         if( $url ) {\r
361                 $return = <<<RETURN\r
362 <tr id="edit-$id" class="edit-row"><td colspan="5"><strong>Original URL</strong>:<input type="text" id="edit-url-$id" name="edit-url-$id" value="$safe_url" class="text" size="70" /> <strong>Short URL</strong>: $www<input type="text" id="edit-keyword-$id" name="edit-keyword-$id" value="$keyword" class="text" size="10" /><br/><strong>Title</strong>: <input type="text" id="edit-title-$id" name="edit-title-$id" value="$safe_title" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-$id" name="edit-submit-$id" value="Save" title="Save new values" class="button" onclick="edit_save('$id');" />&nbsp;<input type="button" id="edit-close-$id" name="edit-close-$id" value="X" title="Cancel editing" class="button" onclick="hide_edit('$id');" /><input type="hidden" id="old_keyword_$id" value="$keyword"/><input type="hidden" id="nonce_$id" value="$nonce"/></td></tr>\r
363 RETURN;\r
364         } else {\r
365                 $return = '<tr><td colspan="6">Error, URL not found</td></tr>';\r
366         }\r
367         \r
368         $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );\r
369 \r
370         return $return;\r
371 }\r
372 \r
373 // Add a link row\r
374 function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) {\r
375         $keyword  = yourls_sanitize_string( $keyword );\r
376         $display_keyword = htmlentities( $keyword );\r
377 \r
378         $url = yourls_sanitize_url( $url );\r
379         $display_url = htmlentities( yourls_trim_long_string( $url ) );\r
380         $title_url = htmlspecialchars( $url );\r
381         \r
382         $title = yourls_sanitize_title( $title ) ;\r
383         $display_title   = yourls_trim_long_string( $title );\r
384         $title = htmlspecialchars( $title );\r
385 \r
386         $id      = yourls_string2htmlid( $keyword ); // used as HTML #id\r
387         $date    = date( 'M d, Y H:i', $timestamp+( YOURLS_HOURS_OFFSET * 3600 ) );\r
388         $clicks  = number_format( $clicks, 0, '', '' );\r
389 \r
390         $shorturl = yourls_link( $keyword );\r
391         $statlink = yourls_statlink( $keyword );\r
392         if( yourls_is_ssl() )\r
393                 $statlink = str_replace( 'http://', 'https://', $statlink );\r
394         \r
395         if( $title ) {\r
396                 $display_link = "<a href=\"$url\" title=\"$title\">$display_title</a><br/><small><a href=\"$url\" title=\"$title_url\">$display_url</a></small>";\r
397         } else {\r
398                 $display_link = "<a href=\"$url\" title=\"$title_url\">$display_url</a>";\r
399         }\r
400         \r
401         $delete_link = yourls_nonce_url( 'delete-link_'.$id,\r
402                 yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) \r
403         );\r
404         \r
405         $edit_link = yourls_nonce_url( 'edit-link_'.$id,\r
406                 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) \r
407         );\r
408         \r
409         // Action button links\r
410         $actions = array(\r
411                 'stats' => array(\r
412                         'href'    => $statlink,\r
413                         'id'      => "statlink-$id",\r
414                         'title'   => 'Stats',\r
415                         'anchor'  => 'Stats',\r
416                 ),\r
417                 'share' => array(\r
418                         'href'    => '',\r
419                         'id'      => "share-button-$id",\r
420                         'title'   => 'Share',\r
421                         'anchor'  => 'Share',\r
422                         'onclick' => "toggle_share('$id');return false;",\r
423                 ),\r
424                 'edit' => array(\r
425                         'href'    => $edit_link,\r
426                         'id'      => "edit-button-$id",\r
427                         'title'   => 'Edit',\r
428                         'anchor'  => 'Edit',\r
429                         'onclick' => "edit('$id');return false;",\r
430                 ),\r
431                 'delete' => array(\r
432                         'href'    => $delete_link,\r
433                         'id'      => "delete-button-$id",\r
434                         'title'   => 'Delete',\r
435                         'anchor'  => 'Delete',\r
436                         'onclick' => "remove('$id');return false;",\r
437                 )\r
438         );\r
439         $actions = yourls_apply_filter( 'table_add_row_action_array', $actions );\r
440         $action_links = '';\r
441         foreach( $actions as $key => $action ) {\r
442                 $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;\r
443                 $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',\r
444                         $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']\r
445                 );\r
446         }\r
447         $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );\r
448         \r
449         $row = <<<ROW\r
450 <tr id="id-$id"><td id="keyword-$id" class="keyword"><a href="$shorturl">$display_keyword</a></td><td id="url-$id" class="url">$display_link</td><td id="timestamp-$id" class="timestamp">$date</td><td id="ip-$id" class="ip">$ip</td><td id="clicks-$id" class="clicks">$clicks</td><td class="actions" id="actions-$id">$action_links<input type="hidden" id="keyword_$id" value="$keyword"/></td></tr>\r
451 ROW;\r
452         $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );\r
453         \r
454         return $row;\r
455 }\r
456 \r
457 // Echo the main table head\r
458 function yourls_table_head() {\r
459         $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";\r
460         echo yourls_apply_filter( 'table_head_start', $start );\r
461         \r
462         $cells = yourls_apply_filter( 'table_head_cells', array(\r
463                 'shorturl' => 'Short URL&nbsp;',\r
464                 'longurl'  => 'Original URL',\r
465                 'date'     => 'Date',\r
466                 'ip'       => 'IP',\r
467                 'clicks'   => 'Clicks&nbsp;&nbsp;',\r
468                 'actions'  => 'Actions'\r
469         ) );\r
470         foreach( $cells as $k => $v ) {\r
471                 echo "<th id='main_table_head_$k'>$v</th>\n";\r
472         }\r
473         \r
474         $end = "</tr></thead>\n";\r
475         echo yourls_apply_filter( 'table_head_end', $end );\r
476 }\r
477 \r
478 // Echo the tbody start tag\r
479 function yourls_table_tbody_start() {\r
480         echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );\r
481 }\r
482 \r
483 // Echo the tbody end tag\r
484 function yourls_table_tbody_end() {\r
485         echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );\r
486 }\r
487 \r
488 // Echo the table start tag\r
489 function yourls_table_end() {\r
490         echo yourls_apply_filter( 'table_end', '</table>' );\r
491 }\r
492 \r
493 // Echo HTML tag for a link\r
494 function yourls_html_link( $href, $title = '', $element = '' ) {\r
495         if( !$title )\r
496                 $title = $href;\r
497         if( $element )\r
498                 $element = "id='$element'";\r
499         echo yourls_apply_filter( 'html_link', "<a href='$href' $element>$title</a>" );\r
500 }\r
501 \r
502 // Display the login screen. Nothing past this point.\r
503 function yourls_login_screen( $error_msg = '' ) {\r
504         yourls_html_head( 'login' );\r
505         \r
506         $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' );\r
507 \r
508         yourls_html_logo();\r
509         ?>\r
510         <div id="login">\r
511                 <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>\r
512                         <?php\r
513                                 if( !empty( $error_msg ) ) {\r
514                                         echo '<p class="error">'.$error_msg.'</p>';\r
515                                 }\r
516                         ?>\r
517                         <p>\r
518                                 <label for="username">Username</label><br />\r
519                                 <input type="text" id="username" name="username" size="30" class="text" />\r
520                         </p>\r
521                         <p>\r
522                                 <label for="password">Password</label><br />\r
523                                 <input type="password" id="password" name="password" size="30" class="text" />\r
524                         </p>\r
525                         <p style="text-align: right;">\r
526                                 <input type="submit" id="submit" name="submit" value="Login" class="button" />\r
527                         </p>\r
528                 </form>\r
529                 <script type="text/javascript">$('#username').focus();</script>\r
530         </div>\r
531         <?php\r
532         yourls_html_footer();\r
533         die();\r
534 }\r
535 \r
536 // Display the admin menu\r
537 function yourls_html_menu() {\r
538 \r
539         // Build menu links\r
540         if( defined( 'YOURLS_USER' ) ) {\r
541                 $logout_link = yourls_apply_filter( 'logout_link', 'Hello <strong>' . YOURLS_USER . '</strong> (<a href="?action=logout" title="Logout">Logout</a>)' );\r
542         } else {\r
543                 $logout_link = yourls_apply_filter( 'logout_link', '' );\r
544         }\r
545         $help_link   = yourls_apply_filter( 'help_link',   '<a href="' . yourls_site_url( false ) .'/readme.html">Help</a>' );\r
546         \r
547         $admin_links    = array();\r
548         $admin_sublinks = array();\r
549         \r
550         $admin_links['admin'] = array(\r
551                 'url'    => yourls_admin_url( 'index.php' ),\r
552                 'title'  => 'Go to the admin interface',\r
553                 'anchor' => 'Admin interface'\r
554         );\r
555         \r
556         if( yourls_is_admin() ) {\r
557                 $admin_links['tools'] = array(\r
558                         'url'    => yourls_admin_url( 'tools.php' ),\r
559                         'anchor' => 'Tools',\r
560                 );\r
561                 $admin_links['plugins'] = array(\r
562                         'url'    => yourls_admin_url( 'plugins.php' ),\r
563                         'anchor' => 'Manage Plugins',\r
564                 );\r
565                 $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages();\r
566         }\r
567         \r
568         $admin_links    = yourls_apply_filter( 'admin_links',    $admin_links );\r
569         $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks );\r
570         \r
571         // Now output menu\r
572         echo '<ul id="admin_menu">'."\n";\r
573         if ( yourls_is_private() && !empty( $logout_link ) )\r
574                 echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>';\r
575 \r
576         foreach( (array)$admin_links as $link => $ar ) {\r
577                 if( isset( $ar['url'] ) ) {\r
578                         $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;\r
579                         $title  = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';\r
580                         printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor );\r
581                 }\r
582                 // Output submenu if any. TODO: clean up, too many code duplicated here\r
583                 if( isset( $admin_sublinks[$link] ) ) {\r
584                         echo "<ul>\n";\r
585                         foreach( $admin_sublinks[$link] as $link => $ar ) {\r
586                                 if( isset( $ar['url'] ) ) {\r
587                                         $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;\r
588                                         $title  = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';\r
589                                         printf( '<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor );\r
590                                 }\r
591                         }\r
592                         echo "</ul>\n";\r
593                 }\r
594         }\r
595         \r
596         if ( isset( $help_link ) )\r
597                 echo '<li id="admin_menu_help_link">' . $help_link .'</li>';\r
598                 \r
599         yourls_do_action( 'admin_menu' );\r
600         echo "</ul>\n";\r
601         yourls_do_action( 'admin_notices' );\r
602         yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'\r
603         /*\r
604         To display a notice:\r
605         $message = "<div>OMG, dude, I mean!</div>" );\r
606         yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );\r
607         */\r
608 }\r
609 \r
610 // Wrapper to admin notices\r
611 function yourls_add_notice( $message, $style = 'notice' ) {\r
612         $message = yourls_notice_box( $message, $style );\r
613         yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );\r
614 }\r
615 \r
616 // Return a formatted notice\r
617 function yourls_notice_box( $message, $style = 'notice' ) {\r
618         return <<<HTML\r
619         <div class="$style">\r
620         <p>$message</p>\r
621         </div>\r
622 HTML;\r
623 }\r
624 \r
625 // Display a page\r
626 function yourls_page( $page ) {\r
627         $include = YOURLS_ABSPATH . "/pages/$page.php";\r
628         if( !file_exists($include) ) {\r
629                 yourls_die( "Page '$page' not found", 'Not found', 404 );\r
630         }\r
631         yourls_do_action( 'pre_page', $page );\r
632         include($include);\r
633         yourls_do_action( 'post_page', $page );\r
634         die();  \r
635 }