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