]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/functions-html.php
Fixed: pagination wasn't holding all parameters. Now officially super neat.
[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 = false;\r
22         \r
23         // Load components as needed\r
24         switch ( $context ) {\r
25                 case 'infos':\r
26                         $share = $tabs = 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="icon" type="image/gif" href="<?php yourls_site_url(); ?>/images/favicon.gif" />\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.6.1.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         <script type="text/javascript">\r
107         //<![CDATA[\r
108                 var ajaxurl  = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';\r
109                 var zclipurl = '<?php yourls_site_url(); ?>/js/ZeroClipboard.swf';\r
110         //]]>\r
111         </script>\r
112         <?php yourls_do_action( 'html_head', $context ); ?>\r
113 </head>\r
114 <body class="<?php echo $context; ?> <?php echo $bodyclass; ?>">\r
115 <div id="wrap">\r
116         <?php\r
117 }\r
118 \r
119 // Display HTML footer (including closing body & html tags)\r
120 function yourls_html_footer() {\r
121         global $ydb;\r
122         \r
123         $num_queries = $ydb->num_queries > 1 ? $ydb->num_queries.' queries' : $ydb->num_queries.' query';\r
124         ?>\r
125         </div> <?php // wrap ?>\r
126         <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
127         <?php if( defined('YOURLS_DEBUG') && YOURLS_DEBUG == true ) {\r
128                 echo '<p>'. $ydb->all_queries .'<p>';\r
129         } ?>\r
130         <?php yourls_do_action( 'html_footer', $ydb->context ); ?>\r
131         </body>\r
132         </html>\r
133         <?php\r
134 }\r
135 \r
136 // Display "Add new URL" box\r
137 function yourls_html_addnew( $url = '', $keyword = '' ) {\r
138         $url = $url ? $url : 'http://';\r
139         ?>\r
140         <div id="new_url">\r
141                 <div>\r
142                         <form id="new_url_form" action="" method="get">\r
143                                 <div><strong>Enter the URL</strong>:<input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" />\r
144                                 Optional: <strong>Custom short URL</strong>:<input type="text" id="add-keyword" name="keyword" value="<?php echo $keyword; ?>" class="text" size="8" />\r
145                                 <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?>\r
146                                 <input type="button" id="add-button" name="add-button" value="Shorten The URL" class="button" onclick="add();" /></div>\r
147                         </form>\r
148                         <div id="feedback" style="display:none"></div>\r
149                 </div>\r
150                 <?php yourls_do_action( 'html_addnew' ); ?>\r
151         </div>\r
152         <?php \r
153 }\r
154 \r
155 // Display main table's footer\r
156 function yourls_html_tfooter( $params = array() ) {\r
157         extract( $params ); // extract $search_text, $page, $search_in_sql ...\r
158 \r
159         ?>\r
160         <tfoot>\r
161                 <tr>\r
162                         <th colspan="6">\r
163                         <div id="filter_form">\r
164                                 <form action="" method="get">\r
165                                         <div id="filter_options">\r
166                                                 Search&nbsp;for&nbsp;\r
167                                                 <input type="text" name="s_search" class="text" size="15" value="<?php echo $search_text; ?>" />\r
168                                                 &nbsp;in&nbsp;\r
169                                                 <select name="s_in" size="1">\r
170                                                         <option value="keyword"<?php if($search_in_sql == 'keyword') { echo ' selected="selected"'; } ?>>Short URL</option>\r
171                                                         <option value="url"<?php if($search_in_sql == 'url') { echo ' selected="selected"'; } ?>>URL</option>\r
172                                                         <option value="title"<?php if($search_in_sql == 'title') { echo ' selected="selected"'; } ?>>Title</option>\r
173                                                         <option value="ip"<?php if($search_in_sql == 'ip') { echo ' selected="selected"'; } ?>>IP</option>\r
174                                                 </select>\r
175                                                 &ndash;&nbsp;Order&nbsp;by&nbsp;\r
176                                                 <select name="s_by" size="1">\r
177                                                         <option value="id"<?php if($sort_by_sql == 'keyword') { echo ' selected="selected"'; } ?>>Short URL</option>\r
178                                                         <option value="url"<?php if($sort_by_sql == 'url') { echo ' selected="selected"'; } ?>>URL</option>\r
179                                                         <option value="timestamp"<?php if($sort_by_sql == 'timestamp') { echo ' selected="selected"'; } ?>>Date</option>\r
180                                                         <option value="ip"<?php if($sort_by_sql == 'ip') { echo ' selected="selected"'; } ?>>IP</option>\r
181                                                         <option value="clicks"<?php if($sort_by_sql == 'clicks') { echo ' selected="selected"'; } ?>>Clicks</option>\r
182                                                 </select>\r
183                                                 <select name="s_order" size="1">\r
184                                                         <option value="asc"<?php if($sort_order_sql == 'asc') { echo ' selected="selected"'; } ?>>Ascending</option>\r
185                                                         <option value="desc"<?php if($sort_order_sql == 'desc') { echo ' selected="selected"'; } ?>>Descending</option>\r
186                                                 </select>\r
187                                                 &ndash;&nbsp;Show&nbsp;\r
188                                                 <input type="text" name="perpage" class="text" size="2" value="<?php echo $perpage; ?>" />&nbsp;rows<br/>\r
189                                                 \r
190                                                 Show links with\r
191                                                 <select name="link_filter" size="1">\r
192                                                         <option value="more"<?php if($link_filter === 'more') { echo ' selected="selected"'; } ?>>more</option>\r
193                                                         <option value="less"<?php if($link_filter === 'less') { echo ' selected="selected"'; } ?>>less</option>\r
194                                                 </select>\r
195                                                 than\r
196                                                 <input type="text" name="link_limit" class="text" size="4" value="<?php echo $link_limit; ?>" />clicks<br/>\r
197                                                 \r
198                                                 Show links created\r
199                                                 <select name="date_filter" id="date_filter" size="1">\r
200                                                         <option value="before"<?php if($date_filter === 'before') { echo ' selected="selected"'; } ?>>before</option>\r
201                                                         <option value="after"<?php if($date_filter === 'after') { echo ' selected="selected"'; } ?>>after</option>\r
202                                                         <option value="between"<?php if($date_filter === 'between') { echo ' selected="selected"'; } ?>> between</option>\r
203                                                 </select>\r
204                                                 <input type="text" name="date_first" id="date_first" class="text" size="12" value="<?php echo $date_first; ?>" />\r
205                                                 <span id="date_and" <?php if($date_filter === 'between') { echo ' style="display:inline"'; } ?>> and </span>\r
206                                                 <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
207                                                 \r
208                                                 <div id="filter_buttons">\r
209                                                         <input type="submit" id="submit-sort" value="Search" class="button primary" />\r
210                                                         &nbsp;\r
211                                                         <input type="button" id="submit-clear-filter" value="Clear" class="button" onclick="window.parent.location.href = 'index.php'" />\r
212                                                 </div>\r
213                                 \r
214                                         </div>\r
215                                 </form>\r
216                         </div>\r
217                         <div id="pagination">\r
218                                 <span class="navigation">\r
219                                 <?php if( $total_pages > 1 ) { ?>\r
220                                         <span class="nav_total"><?php echo $total_pages .' '. yourls_plural( 'page', $total_pages ); ?></span>\r
221                                         <?php\r
222                                         $base_page = yourls_admin_url( 'index.php' );\r
223                                         // Pagination offsets: min( max ( zomg! ) );\r
224                                         $p_start = max(  min( $total_pages - 4, $page - 2 ), 1 );\r
225                                         $p_end = min( max( 5, $page + 2 ), $total_pages );\r
226                                         if( $p_start >= 2 ) {\r
227                                                 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page );\r
228                                                 echo '<span class="nav_link nav_first"><a href="' . $link . '" title="Go to First Page">&laquo; First</a></span>';\r
229                                                 echo '<span class="nav_link nav_prev"></span>';\r
230                                         }\r
231                                         for( $i = $p_start ; $i <= $p_end; $i++ ) {\r
232                                                 if( $i == $page ) {\r
233                                                         echo "<span class='nav_link nav_current'>$i</span>";\r
234                                                 } else {\r
235                                                         $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page );\r
236                                                         echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="Page '.$i.'">'.$i.'</a></span>';\r
237                                                 }\r
238                                         }\r
239                                         if( ( $p_end ) < $total_pages ) {\r
240                                                 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page );\r
241                                                 echo '<span class="nav_link nav_next"></span>';\r
242                                                 echo '<span class="nav_link nav_last"><a href="' . $link . '" title="Go to Last Page">Last &raquo;</a></span>';\r
243                                         }\r
244                                         ?>\r
245                                 <?php } ?>\r
246                                 </span>\r
247                         </div>\r
248                         </th>\r
249                 </tr>\r
250                 <?php yourls_do_action( 'html_tfooter' ); ?>\r
251         </tfoot>\r
252         <?php\r
253 }\r
254 \r
255 // Display the Quick Share box\r
256 function yourls_share_box( $longurl, $shorturl, $title='', $text='', $shortlink_title = '<h2>Your short link</h2>', $share_title = '<h2>Quick Share</h2>', $hidden = false ) {\r
257         // Allow plugins to short-circuit the whole function\r
258         $pre = yourls_apply_filter( 'shunt_share_box', false );\r
259         if ( false !== $pre )\r
260                 return $pre;\r
261                 \r
262         $text = ( $text ? '"'.$text.'" ' : '' );\r
263         $title = ( $title ? "$title " : '' );\r
264         $share = htmlspecialchars_decode( $title.$text.$shorturl );\r
265         $count = 140 - strlen( $share );\r
266         $hidden = ( $hidden ? 'style="display:none;"' : '' );\r
267         \r
268         // Allow plugins to filter all data\r
269         $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );\r
270         $data = yourls_apply_filter( 'share_box_data', $data );\r
271         extract( $data );\r
272         \r
273         $_share = rawurlencode( $share );\r
274         $_url = rawurlencode( $shorturl );\r
275         ?>\r
276         \r
277         <div id="shareboxes" <?php echo $hidden; ?>>\r
278 \r
279                 <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>\r
280 \r
281                 <div id="copybox" class="share">\r
282                 <?php echo $shortlink_title; ?>\r
283                         <p><input id="copylink" class="text" size="40" value="<?php echo $shorturl; ?>" /></p>\r
284                         <p><small>Long link: <a id="origlink" href="<?php echo $longurl; ?>"><?php echo $longurl; ?></a></small>\r
285                         <?php if( yourls_do_log_redirect() ) { ?>\r
286                         <br/><small>Stats: <a id="statlink" href="<?php echo $shorturl; ?>+"><?php echo $shorturl; ?>+</a></small>\r
287                         <input type="hidden" id="titlelink" value="<?php echo $title; ?>" />\r
288                         <?php } ?>\r
289                         </p>\r
290                 </div>\r
291 \r
292                 <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>\r
293 \r
294                 <div id="sharebox" class="share">\r
295                         <?php echo $share_title; ?>\r
296                         <div id="tweet">\r
297                                 <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>\r
298                                 <textarea id="tweet_body"><?php echo $share; ?></textarea>\r
299                         </div>\r
300                         <p id="share_links">Share with \r
301                                 <a id="share_tw" href="http://twitter.com/home?status=<?php echo $_share; ?>" title="Tweet this!" onclick="share('tw');return false">Twitter</a>\r
302                                 <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
303                                 <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
304                                 <?php\r
305                                 yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );\r
306                                 // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.\r
307                                 ?>\r
308                         </p>\r
309                 </div>\r
310                 \r
311                 <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>\r
312         \r
313         </div>\r
314         \r
315         <?php\r
316 }\r
317 \r
318 // Die die die\r
319 function yourls_die( $message = '', $title = '', $header_code = 200 ) {\r
320         yourls_status_header( $header_code );\r
321         \r
322         yourls_html_head();\r
323         yourls_html_logo();\r
324         echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" );\r
325         echo yourls_apply_filter( 'die_message', "<p>$message</p>" );\r
326         yourls_do_action( 'yourls_die' );\r
327         yourls_html_footer();\r
328         die();\r
329 }\r
330 \r
331 // Add the "Edit" row\r
332 function yourls_table_edit_row( $keyword ) {\r
333         global $ydb;\r
334         \r
335         $table = YOURLS_DB_TABLE_URL;\r
336         $keyword = yourls_sanitize_string( $keyword );\r
337         $id = yourls_string2htmlid( $keyword ); // used as HTML #id\r
338         $url = yourls_get_keyword_longurl( $keyword );\r
339         $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );\r
340         $safe_url = stripslashes( $url );\r
341         $safe_title = stripslashes( $title );\r
342         $www = yourls_link();\r
343         \r
344         $save_link = yourls_nonce_url( 'save-link_'.$id,\r
345                 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit_save', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) \r
346         );\r
347         \r
348         $nonce = yourls_create_nonce( 'edit-save_'.$id );\r
349         \r
350         if( $url ) {\r
351                 $return = <<<RETURN\r
352 <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
353 RETURN;\r
354         } else {\r
355                 $return = '<tr><td colspan="6">Error, URL not found</td></tr>';\r
356         }\r
357         \r
358         $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );\r
359 \r
360         return $return;\r
361 }\r
362 \r
363 // Add a link row\r
364 function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) {\r
365         $keyword  = yourls_sanitize_string( $keyword );\r
366         $display_keyword = htmlentities( $keyword );\r
367 \r
368         $url = yourls_sanitize_url( $url );\r
369         $display_url = htmlentities( yourls_trim_long_string( $url ) );\r
370         $title_url = htmlspecialchars( $url );\r
371         \r
372         $title = yourls_sanitize_title( $title ) ;\r
373         $display_title   = yourls_trim_long_string( $title );\r
374         $title = htmlspecialchars( $title );\r
375 \r
376         $id      = yourls_string2htmlid( $keyword ); // used as HTML #id\r
377         $date    = date( 'M d, Y H:i', $timestamp+( YOURLS_HOURS_OFFSET * 3600 ) );\r
378         $clicks  = number_format( $clicks, 0, '', '' );\r
379 \r
380         $shorturl = yourls_link( $keyword );\r
381         $statlink = yourls_statlink( $keyword );\r
382         if( yourls_is_ssl() )\r
383                 $statlink = str_replace( 'http://', 'https://', $statlink );\r
384         \r
385         if( $title ) {\r
386                 $display_link = "<a href=\"$url\" title=\"$title\">$display_title</a><br/><small><a href=\"$url\" title=\"$title_url\">$display_url</a></small>";\r
387         } else {\r
388                 $display_link = "<a href=\"$url\" title=\"$title_url\">$display_url</a>";\r
389         }\r
390         \r
391         $delete_link = yourls_nonce_url( 'delete-link_'.$id,\r
392                 yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) \r
393         );\r
394         \r
395         $edit_link = yourls_nonce_url( 'edit-link_'.$id,\r
396                 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) \r
397         );\r
398         \r
399         // Action button links\r
400         $actions = array(\r
401                 'stats' => array(\r
402                         'href'    => $statlink,\r
403                         'id'      => "statlink-$id",\r
404                         'title'   => 'Stats',\r
405                         'anchor'  => 'Stats',\r
406                 ),\r
407                 'share' => array(\r
408                         'href'    => '',\r
409                         'id'      => "share-button-$id",\r
410                         'title'   => 'Share',\r
411                         'anchor'  => 'Share',\r
412                         'onclick' => "toggle_share('$id');return false;",\r
413                 ),\r
414                 'edit' => array(\r
415                         'href'    => $edit_link,\r
416                         'id'      => "edit-button-$id",\r
417                         'title'   => 'Edit',\r
418                         'anchor'  => 'Edit',\r
419                         'onclick' => "edit('$id');return false;",\r
420                 ),\r
421                 'delete' => array(\r
422                         'href'    => $delete_link,\r
423                         'id'      => "delete-button-$id",\r
424                         'title'   => 'Delete',\r
425                         'anchor'  => 'Delete',\r
426                         'onclick' => "remove('$id');return false;",\r
427                 )\r
428         );\r
429         $actions = yourls_apply_filter( 'table_add_row_action_array', $actions );\r
430         $action_links = '';\r
431         foreach( $actions as $key => $action ) {\r
432                 $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;\r
433                 $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',\r
434                         $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']\r
435                 );\r
436         }\r
437         $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );\r
438         \r
439         $row = <<<ROW\r
440 <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
441 ROW;\r
442         $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );\r
443         \r
444         return $row;\r
445 }\r
446 \r
447 // Echo the main table head\r
448 function yourls_table_head() {\r
449         $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";\r
450         echo yourls_apply_filter( 'table_head_start', $start );\r
451         \r
452         $cells = yourls_apply_filter( 'table_head_cells', array(\r
453                 'shorturl' => 'Short URL&nbsp;',\r
454                 'longurl'  => 'Original URL',\r
455                 'date'     => 'Date',\r
456                 'ip'       => 'IP',\r
457                 'clicks'   => 'Clicks&nbsp;&nbsp;',\r
458                 'actions'  => 'Actions'\r
459         ) );\r
460         foreach( $cells as $k => $v ) {\r
461                 echo "<th id='main_table_head_$k'>$v</th>\n";\r
462         }\r
463         \r
464         $end = "</tr></thead>\n";\r
465         echo yourls_apply_filter( 'table_head_end', $end );\r
466 }\r
467 \r
468 // Echo the tbody start tag\r
469 function yourls_table_tbody_start() {\r
470         echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );\r
471 }\r
472 \r
473 // Echo the tbody end tag\r
474 function yourls_table_tbody_end() {\r
475         echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );\r
476 }\r
477 \r
478 // Echo the table start tag\r
479 function yourls_table_end() {\r
480         echo yourls_apply_filter( 'table_end', '</table>' );\r
481 }\r
482 \r
483 // Echo HTML tag for a link\r
484 function yourls_html_link( $href, $title = '', $element = '' ) {\r
485         if( !$title )\r
486                 $title = $href;\r
487         if( $element )\r
488                 $element = "id='$element'";\r
489         echo yourls_apply_filter( 'html_link', "<a href='$href' $element>$title</a>" );\r
490 }\r
491 \r
492 // Display the login screen. Nothing past this point.\r
493 function yourls_login_screen( $error_msg = '' ) {\r
494         yourls_html_head( 'login' );\r
495         \r
496         $action = ( isset($_GET['action']) && $_GET['action'] == 'logout' ? '?' : '' );\r
497 \r
498         yourls_html_logo();\r
499         ?>\r
500         <div id="login">\r
501                 <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>\r
502                         <?php\r
503                                 if(!empty($error_msg)) {\r
504                                         echo '<p class="error">'.$error_msg.'</p>';\r
505                                 }\r
506                         ?>\r
507                         <p>\r
508                                 <label for="username">Username</label><br />\r
509                                 <input type="text" id="username" name="username" size="30" class="text" />\r
510                         </p>\r
511                         <p>\r
512                                 <label for="password">Password</label><br />\r
513                                 <input type="password" id="password" name="password" size="30" class="text" />\r
514                         </p>\r
515                         <p style="text-align: right;">\r
516                                 <input type="submit" id="submit" name="submit" value="Login" class="button" />\r
517                         </p>\r
518                 </form>\r
519                 <script type="text/javascript">$('#username').focus();</script>\r
520         </div>\r
521         <?php\r
522         yourls_html_footer();\r
523         die();\r
524 }\r
525 \r
526 // Display the admin menu\r
527 function yourls_html_menu() {\r
528         ?>\r
529         <ul id="admin_menu">\r
530         <?php if ( yourls_is_private() ) { ?>\r
531                 <li>Hello <strong><?php echo YOURLS_USER; ?></strong> (<a href="?action=logout" title="Logout">Logout</a>)</li>\r
532         <?php } ?>\r
533                 <li><a href="<?php echo yourls_admin_url('index.php') ?>">Admin Interface</a></li>\r
534         <?php if( yourls_is_admin() ) { ?>\r
535                 <li><a href="<?php echo yourls_admin_url('tools.php'); ?>">Tools</a></li>\r
536                 <li><a href="<?php echo yourls_admin_url('plugins.php'); ?>">Plugins</a></li>\r
537                 <?php yourls_list_plugin_admin_pages(); ?>      \r
538                 <li><a href="<?php yourls_site_url(); ?>/readme.html">Help</a></li>\r
539                 <?php yourls_do_action( 'admin_menu' ); ?>\r
540         <?php } ?>\r
541         </ul>\r
542         <?php\r
543         yourls_do_action( 'admin_notices' );\r
544         yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'\r
545         /*\r
546         To display a notice:\r
547         $message = "<div>OMG, dude, I mean!</div>" );\r
548         yourls_add_action('admin_notices', create_function( '', "echo '$message';" ) );\r
549         */\r
550 }\r
551 \r
552 // Wrapper to admin notices\r
553 function yourls_add_notice( $message ) {\r
554         $message = yourls_notice_box( $message );\r
555         yourls_add_action('admin_notices', create_function( '', "echo '$message';" ) );\r
556 }\r
557 \r
558 // Return a formatted notice\r
559 function yourls_notice_box( $message ) {\r
560         return <<<HTML\r
561         <div class="notice">\r
562         <p>$message</p>\r
563         </div>\r
564 HTML;\r
565 }\r
566 \r
567 // Display a page\r
568 function yourls_page( $page ) {\r
569         $include = YOURLS_ABSPATH . "/pages/$page.php";\r
570         if (!file_exists($include)) {\r
571                 yourls_die("Page '$page' not found", 'Not found', 404);\r
572         }\r
573         yourls_do_action( 'pre_page', $page );\r
574         include($include);\r
575         yourls_do_action( 'post_page', $page );\r
576         die();  \r
577 }\r
578 \r