3 // Display <h1> header and logo
\r
4 function yourls_html_logo() {
\r
5 yourls_do_action( 'pre_html_logo' );
\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
12 yourls_do_action( 'html_logo' );
\r
15 // Display HTML head and <body> tag
\r
16 function yourls_html_head( $context = 'index', $title = '' ) {
\r
18 yourls_do_action( 'pre_html_head', $context, $title );
\r
20 // All components to false, except when specified true
\r
21 $share = $insert = $tablesorter = $tabs = $cal = $charts = false;
\r
23 // Load components as needed
\r
24 switch ( $context ) {
\r
26 $share = $tabs = $charts = true;
\r
30 $share = $insert = $tablesorter = true;
\r
34 $insert = $tablesorter = $cal = $share = true;
\r
39 $tablesorter = true;
\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
58 // Store page context in global object
\r
60 $ydb->context = $context;
\r
63 $bodyclass = yourls_apply_filter( 'bodyclass', '' );
\r
64 $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' );
\r
67 $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link();
\r
68 $title = $title ? $title . " « " . $_title : $_title;
\r
69 $title = yourls_apply_filter( 'html_title', $title, $context );
\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
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="IE-9"/>
\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 « YOURLS » 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
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
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
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
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
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']});
\r
112 <script type="text/javascript">
\r
114 var ajaxurl = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';
\r
115 var zclipurl = '<?php yourls_site_url(); ?>/js/ZeroClipboard.swf';
\r
118 <?php yourls_do_action( 'html_head', $context ); ?>
\r
120 <body class="<?php echo $context; ?> <?php echo $bodyclass; ?>">
\r
125 // Display HTML footer (including closing body & html tags)
\r
126 function yourls_html_footer() {
\r
129 $num_queries = $ydb->num_queries > 1 ? $ydb->num_queries.' queries' : $ydb->num_queries.' query';
\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 ' – '.$num_queries; ?></p></div>
\r
133 <?php if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) {
\r
134 echo '<p>'. $ydb->all_queries .'<p>';
\r
136 <?php yourls_do_action( 'html_footer', $ydb->context ); ?>
\r
142 // Display "Add new URL" box
\r
143 function yourls_html_addnew( $url = '', $keyword = '' ) {
\r
144 $url = $url ? $url : 'http://';
\r
148 <form id="new_url_form" action="" method="get">
\r
149 <div><strong><?php yourls_e('Enter the URL'); ?></strong>:<input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" />
\r
150 <?php yourls_e('Optional'); ?>: <strong><?php yourls_e('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="<?php yourls_e('Shorten The URL'); ?>" class="button" onclick="add();" /></div>
\r
154 <div id="feedback" style="display:none"></div>
\r
156 <?php yourls_do_action( 'html_addnew' ); ?>
\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
169 <div id="filter_form">
\r
170 <form action="" method="get">
\r
171 <div id="filter_options">
\r
172 <?php yourls_e('Search for '); ?>
\r
173 <input type="text" name="s_search" class="text" size="12" value="<?php echo $search_text; ?>" />
\r
174 <?php yourls_e(' in '); ?>
\r
175 <select name="s_in" size="1">
\r
176 <option value="keyword"<?php if($search_in_sql == 'keyword') { echo ' selected="selected"'; } ?>><?php yourls_e('Short URL'); ?></option>
\r
177 <option value="url"<?php if($search_in_sql == 'url') { echo ' selected="selected"'; } ?>><?php yourls_e('URL'); ?></option>
\r
178 <option value="title"<?php if($search_in_sql == 'title') { echo ' selected="selected"'; } ?>><?php yourls_e('Title'); ?></option>
\r
179 <option value="ip"<?php if($search_in_sql == 'ip') { echo ' selected="selected"'; } ?>><?php yourls_e('IP'); ?></option>
\r
181 – <?php yourls_e('Order by'); ?>
\r
182 <select name="s_by" size="1">
\r
183 <option value="id"<?php if($sort_by_sql == 'keyword') { echo ' selected="selected"'; } ?>><?php yourls_e('Short URL'); ?></option>
\r
184 <option value="url"<?php if($sort_by_sql == 'url') { echo ' selected="selected"'; } ?>><?php yourls_e('URL'); ?></option>
\r
185 <option value="timestamp"<?php if($sort_by_sql == 'timestamp') { echo ' selected="selected"'; } ?>><?php yourls_e('Date'); ?></option>
\r
186 <option value="ip"<?php if($sort_by_sql == 'ip') { echo ' selected="selected"'; } ?>><?php yourls_e('IP'); ?></option>
\r
187 <option value="clicks"<?php if($sort_by_sql == 'clicks') { echo ' selected="selected"'; } ?>><?php yourls_e('Clicks'); ?></option>
\r
189 <select name="s_order" size="1">
\r
190 <option value="asc"<?php if($sort_order_sql == 'asc') { echo ' selected="selected"'; } ?>><?php yourls_e('Ascending'); ?></option>
\r
191 <option value="desc"<?php if($sort_order_sql == 'desc') { echo ' selected="selected"'; } ?>><?php yourls_e('Descending'); ?></option>
\r
193 – <?php yourls_e('Show'); ?>
\r
194 <input type="text" name="perpage" class="text" size="2" value="<?php echo $perpage; ?>" /> <?php yourls_e('rows'); ?><br/>
\r
196 <?php yourls_e('Show links with'); ?>
\r
197 <select name="link_filter" size="1">
\r
198 <option value="more"<?php if($link_filter === 'more') { echo ' selected="selected"'; } ?>><?php yourls_e('more'); ?></option>
\r
199 <option value="less"<?php if($link_filter === 'less') { echo ' selected="selected"'; } ?>><?php yourls_e('less'); ?></option>
\r
201 <?php yourls_e('than'); ?>
\r
202 <input type="text" name="link_limit" class="text" size="4" value="<?php echo $link_limit; ?>" /> <?php yourls_e('clicks'); ?><br/>
\r
204 <?php yourls_e('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"'; } ?>><?php yourls_e('before'); ?></option>
\r
207 <option value="after"<?php if($date_filter === 'after') { echo ' selected="selected"'; } ?>><?php yourls_e('after'); ?></option>
\r
208 <option value="between"<?php if($date_filter === 'between') { echo ' selected="selected"'; } ?>><?php yourls_e('between'); ?></option>
\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
214 <div id="filter_buttons">
\r
215 <input type="submit" id="submit-sort" value="<?php yourls_e('Search'); ?>" class="button primary" />
\r
217 <input type="button" id="submit-clear-filter" value="<?php yourls_e('Clear'); ?>" class="button" onclick="window.parent.location.href = 'index.php'" />
\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( yourls__('page'), $total_pages ); ?></span>
\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="' . yourls__('Go to First Page') . '">« First</a></span>';
\r
235 echo '<span class="nav_link nav_prev"></span>';
\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
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
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="' . yourls__('Go to First Page') . '">Last »</a></span>';
\r
256 <?php yourls_do_action( 'html_tfooter' ); ?>
\r
261 // Display the Quick Share box
\r
262 function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) {
\r
263 if ($shortlink_title == '')
\r
264 $shortlink_title = '<h2>' . yourls__('Your short link') . '</h2>';
\r
265 if ($share_title == '')
\r
266 $share_title = '<h2>' . yourls__('Quick Share') . '</h2>';
\r
268 // Allow plugins to short-circuit the whole function
\r
269 $pre = yourls_apply_filter( 'shunt_share_box', false );
\r
270 if ( false !== $pre )
\r
273 $text = ( $text ? '"'.$text.'" ' : '' );
\r
274 $title = ( $title ? "$title " : '' );
\r
275 $share = yourls_esc_textarea( $title.$text.$shorturl );
\r
276 $count = 140 - strlen( $share );
\r
277 $hidden = ( $hidden ? 'style="display:none;"' : '' );
\r
279 // Allow plugins to filter all data
\r
280 $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );
\r
281 $data = yourls_apply_filter( 'share_box_data', $data );
\r
284 $_share = rawurlencode( $share );
\r
285 $_url = rawurlencode( $shorturl );
\r
288 <div id="shareboxes" <?php echo $hidden; ?>>
\r
290 <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>
\r
292 <div id="copybox" class="share">
\r
293 <?php echo $shortlink_title; ?>
\r
294 <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p>
\r
295 <p><small><?php yourls_e('Long link'); ?>: <a id="origlink" href="<?php echo yourls_esc_url( $longurl ); ?>"><?php echo yourls_esc_url( $longurl ); ?></a></small>
\r
296 <?php if( yourls_do_log_redirect() ) { ?>
\r
297 <br/><small><?php yourls_e('Stats'); ?>: <a id="statlink" href="<?php echo yourls_esc_url( $shorturl ); ?>+"><?php echo yourls_esc_url( $shorturl ); ?>+</a></small>
\r
298 <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" />
\r
303 <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>
\r
305 <div id="sharebox" class="share">
\r
306 <?php echo $share_title; ?>
\r
308 <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>
\r
309 <textarea id="tweet_body"><?php echo $share; ?></textarea>
\r
311 <p id="share_links"><?php yourls_e('Share with'); ?>
\r
312 <a id="share_tw" href="http://twitter.com/home?status=<?php echo $_share; ?>" title="Tweet this!" onclick="share('tw');return false">Twitter</a>
\r
313 <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
314 <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
316 yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );
\r
317 // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.
\r
322 <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>
\r
330 function yourls_die( $message = '', $title = '', $header_code = 200 ) {
\r
331 yourls_status_header( $header_code );
\r
333 if( !yourls_did_action( 'html_head' ) ) {
\r
334 yourls_html_head();
\r
335 yourls_html_logo();
\r
337 echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" );
\r
338 echo yourls_apply_filter( 'die_message', "<p>$message</p>" );
\r
339 yourls_do_action( 'yourls_die' );
\r
340 if( !yourls_did_action( 'html_head' ) ) {
\r
341 yourls_html_footer();
\r
346 // Add the "Edit" row
\r
347 function yourls_table_edit_row( $keyword ) {
\r
350 $table = YOURLS_DB_TABLE_URL;
\r
351 $keyword = yourls_sanitize_string( $keyword );
\r
352 $id = yourls_string2htmlid( $keyword ); // used as HTML #id
\r
353 $url = yourls_get_keyword_longurl( $keyword );
\r
355 $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );
\r
356 $safe_url = yourls_esc_attr( $url );
\r
357 $safe_title = yourls_esc_attr( $title );
\r
358 $www = yourls_link();
\r
360 $save_link = yourls_nonce_url( 'save-link_'.$id,
\r
361 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit_save', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
\r
364 $nonce = yourls_create_nonce( 'edit-save_'.$id );
\r
367 $return = <<<RETURN
\r
368 <tr id="edit-$id" class="edit-row"><td colspan="5"><strong>Long URL</strong>:<input type="text" id="edit-url-$id" name="edit-url-$id" value="$safe_url" class="text" size="70" /><br/><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');" /> <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
371 $return = '<tr><td colspan="6">' . yourls__('Error, URL not found') . '</td></tr>';
\r
374 $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );
\r
380 function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) {
\r
381 $keyword = yourls_sanitize_string( $keyword );
\r
382 $id = yourls_string2htmlid( $keyword ); // used as HTML #id
\r
383 $shorturl = yourls_link( $keyword );
\r
385 $statlink = yourls_statlink( $keyword );
\r
387 $delete_link = yourls_nonce_url( 'delete-link_'.$id,
\r
388 yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
\r
391 $edit_link = yourls_nonce_url( 'edit-link_'.$id,
\r
392 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
\r
395 // Action link buttons: the array
\r
398 'href' => $statlink,
\r
399 'id' => "statlink-$id",
\r
400 'title' => yourls_esc_attr__( 'Stats' ),
\r
401 'anchor' => yourls__( 'Stats' ),
\r
405 'id' => "share-button-$id",
\r
406 'title' => yourls_esc_attr__( 'Share' ),
\r
407 'anchor' => yourls__( 'Share' ),
\r
408 'onclick' => "toggle_share('$id');return false;",
\r
411 'href' => $edit_link,
\r
412 'id' => "edit-button-$id",
\r
413 'title' => yourls_esc_attr__( 'Edit' ),
\r
414 'anchor' => yourls__( 'Edit' ),
\r
415 'onclick' => "edit('$id');return false;",
\r
418 'href' => $delete_link,
\r
419 'id' => "delete-button-$id",
\r
420 'title' => yourls_esc_attr__( 'Delete' ),
\r
421 'anchor' => yourls__( 'Delete' ),
\r
422 'onclick' => "remove('$id');return false;",
\r
425 $actions = yourls_apply_filter( 'table_add_row_action_array', $actions );
\r
427 // Action link buttons: the HTML
\r
428 $action_links = '';
\r
429 foreach( $actions as $key => $action ) {
\r
430 $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;
\r
431 $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',
\r
432 $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']
\r
435 $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );
\r
440 $protocol_warning = '';
\r
441 if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) )
\r
442 $protocol_warning = yourls_apply_filters( 'add_row_protocol_warning', '<span class="warning" title="Not a common link">★</span>' );
\r
444 // Row cells: the array
\r
446 'keyword' => array(
\r
447 'template' => '<a href="%shorturl%">%keyword_html%</a>',
\r
448 'shorturl' => yourls_esc_url( $shorturl ),
\r
449 'keyword_html' => yourls_esc_html( $keyword ),
\r
452 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>',
\r
453 'long_url' => yourls_esc_url( $url ),
\r
454 'title_attr' => yourls_esc_attr( $title ),
\r
455 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ),
\r
456 'long_url_html' => yourls_esc_html( yourls_trim_long_string( $url ) ),
\r
457 'warning' => $protocol_warning,
\r
459 'timestamp' => array(
\r
460 'template' => '%date%',
\r
461 'date' => date( 'M d, Y H:i', $timestamp +( YOURLS_HOURS_OFFSET * 3600 ) ),
\r
464 'template' => '%ip%',
\r
468 'template' => '%clicks%',
\r
469 'clicks' => number_format( $clicks, 0, '', '' ),
\r
471 'actions' => array(
\r
472 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>',
\r
473 'actions' => $action_links,
\r
475 'keyword' => $keyword,
\r
478 $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp );
\r
480 // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value.
\r
481 $row = "<tr id=\"id-$id\">";
\r
482 foreach( $cells as $cell_id => $elements ) {
\r
483 $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id );
\r
484 $row .= preg_replace( '/%([^%]+)?%/e', '$elements["$1"]', $elements['template'] );
\r
488 $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );
\r
493 // Echo the main table head
\r
494 function yourls_table_head() {
\r
495 $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";
\r
496 echo yourls_apply_filter( 'table_head_start', $start );
\r
498 $cells = yourls_apply_filter( 'table_head_cells', array(
\r
499 'shorturl' => yourls__('Short URL '),
\r
500 'longurl' => yourls__('Original URL'),
\r
501 'date' => yourls__('Date'),
\r
502 'ip' => yourls__('IP'),
\r
503 'clicks' => yourls__('Clicks '),
\r
504 'actions' => yourls__('Actions')
\r
506 foreach( $cells as $k => $v ) {
\r
507 echo "<th id='main_table_head_$k'>$v</th>\n";
\r
510 $end = "</tr></thead>\n";
\r
511 echo yourls_apply_filter( 'table_head_end', $end );
\r
514 // Echo the tbody start tag
\r
515 function yourls_table_tbody_start() {
\r
516 echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );
\r
519 // Echo the tbody end tag
\r
520 function yourls_table_tbody_end() {
\r
521 echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );
\r
524 // Echo the table start tag
\r
525 function yourls_table_end() {
\r
526 echo yourls_apply_filter( 'table_end', '</table>' );
\r
529 // Echo HTML tag for a link
\r
530 function yourls_html_link( $href, $title = '', $element = '' ) {
\r
534 $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) );
\r
535 $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) );
\r
536 echo yourls_apply_filter( 'html_link', $link );
\r
539 // Display the login screen. Nothing past this point.
\r
540 function yourls_login_screen( $error_msg = '' ) {
\r
541 yourls_html_head( 'login' );
\r
543 $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' );
\r
545 yourls_html_logo();
\r
548 <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>
\r
550 if( !empty( $error_msg ) ) {
\r
551 echo '<p class="error">'.$error_msg.'</p>';
\r
555 <label for="username"><?php yourls_e('Username'); ?></label><br />
\r
556 <input type="text" id="username" name="username" size="30" class="text" />
\r
559 <label for="password"><?php yourls_e('Password'); ?></label><br />
\r
560 <input type="password" id="password" name="password" size="30" class="text" />
\r
562 <p style="text-align: right;">
\r
563 <input type="submit" id="submit" name="submit" value="<?php yourls_e('Login'); ?>" class="button" />
\r
566 <script type="text/javascript">$('#username').focus();</script>
\r
569 yourls_html_footer();
\r
573 // Display the admin menu
\r
574 function yourls_html_menu() {
\r
576 // Build menu links
\r
577 if( defined( 'YOURLS_USER' ) ) {
\r
578 $logout_link = yourls_apply_filter( 'logout_link', yourls__('Hello') . ' <strong>' . YOURLS_USER . '</strong> (<a href="?action=logout" title="Logout">' . yourls__('Logout') . '</a>)' );
\r
580 $logout_link = yourls_apply_filter( 'logout_link', '' );
\r
582 $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__('Help') . '</a>' );
\r
584 $admin_links = array();
\r
585 $admin_sublinks = array();
\r
587 $admin_links['admin'] = array(
\r
588 'url' => yourls_admin_url( 'index.php' ),
\r
589 'title' => yourls__('Go to the admin interface'),
\r
590 'anchor' => yourls__('Admin interface')
\r
593 if( yourls_is_admin() ) {
\r
594 $admin_links['tools'] = array(
\r
595 'url' => yourls_admin_url( 'tools.php' ),
\r
596 'anchor' => yourls__('Tools')
\r
598 $admin_links['plugins'] = array(
\r
599 'url' => yourls_admin_url( 'plugins.php' ),
\r
600 'anchor' => yourls__('Manage Plugins')
\r
602 $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages();
\r
605 $admin_links = yourls_apply_filter( 'admin_links', $admin_links );
\r
606 $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks );
\r
609 echo '<ul id="admin_menu">'."\n";
\r
610 if ( yourls_is_private() && !empty( $logout_link ) )
\r
611 echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>';
\r
613 foreach( (array)$admin_links as $link => $ar ) {
\r
614 if( isset( $ar['url'] ) ) {
\r
615 $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
\r
616 $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
\r
617 printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor );
\r
619 // Output submenu if any. TODO: clean up, too many code duplicated here
\r
620 if( isset( $admin_sublinks[$link] ) ) {
\r
622 foreach( $admin_sublinks[$link] as $link => $ar ) {
\r
623 if( isset( $ar['url'] ) ) {
\r
624 $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
\r
625 $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
\r
626 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
633 if ( isset( $help_link ) )
\r
634 echo '<li id="admin_menu_help_link">' . $help_link .'</li>';
\r
636 yourls_do_action( 'admin_menu' );
\r
638 yourls_do_action( 'admin_notices' );
\r
639 yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'
\r
641 To display a notice:
\r
642 $message = "<div>OMG, dude, I mean!</div>" );
\r
643 yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );
\r
647 // Wrapper to admin notices
\r
648 function yourls_add_notice( $message, $style = 'notice' ) {
\r
649 $message = yourls_notice_box( $message, $style );
\r
650 yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );
\r
653 // Return a formatted notice
\r
654 function yourls_notice_box( $message, $style = 'notice' ) {
\r
656 <div class="$style">
\r
663 function yourls_page( $page ) {
\r
664 $include = YOURLS_ABSPATH . "/pages/$page.php";
\r
665 if( !file_exists($include) ) {
\r
666 yourls_die( "Page '$page' not found", 'Not found', 404 );
\r
668 yourls_do_action( 'pre_page', $page );
\r
670 yourls_do_action( 'post_page', $page );
\r