4 * Display <h1> header and logo
\r
7 function yourls_html_logo() {
\r
8 yourls_do_action( 'pre_html_logo' );
\r
11 <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
12 <img src="<?php yourls_site_url(); ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" border="0" style="border: 0px;" /></a>
\r
15 yourls_do_action( 'html_logo' );
\r
19 * Display HTML head and <body> tag
\r
21 * @param string $context Context of the page (stats, index, infos, ...)
\r
22 * @param string $title HTML title of the page
\r
24 function yourls_html_head( $context = 'index', $title = '' ) {
\r
26 yourls_do_action( 'pre_html_head', $context, $title );
\r
28 // All components to false, except when specified true
\r
29 $share = $insert = $tablesorter = $tabs = $cal = $charts = false;
\r
31 // Load components as needed
\r
32 switch ( $context ) {
\r
34 $share = $tabs = $charts = true;
\r
38 $share = $insert = $tablesorter = true;
\r
42 $insert = $tablesorter = $cal = $share = true;
\r
47 $tablesorter = true;
\r
57 // Force no cache for all admin pages
\r
58 if( yourls_is_admin() && !headers_sent() ) {
\r
59 header( 'Expires: Thu, 23 Mar 1972 07:00:00 GMT' );
\r
60 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
\r
61 header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
\r
62 header( 'Pragma: no-cache' );
\r
63 yourls_do_action( 'admin_headers', $context, $title );
\r
66 // Store page context in global object
\r
68 $ydb->context = $context;
\r
71 $bodyclass = yourls_apply_filter( 'bodyclass', '' );
\r
72 $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' );
\r
75 $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link();
\r
76 $title = $title ? $title . " « " . $_title : $_title;
\r
77 $title = yourls_apply_filter( 'html_title', $title, $context );
\r
80 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
81 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
\r
83 <title><?php echo $title ?></title>
\r
84 <link rel="shortcut icon" href="<?php yourls_favicon(); ?>" />
\r
85 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
86 <meta http-equiv="X-UA-Compatible" content="IE-9"/>
\r
87 <meta name="author" content="Ozh RICHARD & Lester CHAN for http://yourls.org/" />
\r
88 <meta name="generator" content="YOURLS <?php echo YOURLS_VERSION ?>" />
\r
89 <meta name="description" content="Insert URL « YOURLS » Your Own URL Shortener' | <?php yourls_site_url(); ?>" />
\r
90 <script src="<?php yourls_site_url(); ?>/js/jquery-1.8.2.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
91 <script src="<?php yourls_site_url(); ?>/js/common.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
92 <script src="<?php yourls_site_url(); ?>/js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
93 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
\r
94 <?php if ( $tabs ) { ?>
\r
95 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
\r
96 <script src="<?php yourls_site_url(); ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
98 <?php if ( $tablesorter ) { ?>
\r
99 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
\r
100 <script src="<?php yourls_site_url(); ?>/js/jquery.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
102 <?php if ( $insert ) { ?>
\r
103 <script src="<?php yourls_site_url(); ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
105 <?php if ( $share ) { ?>
\r
106 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
\r
107 <script src="<?php yourls_site_url(); ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
108 <script src="<?php yourls_site_url(); ?>/js/jquery.zclip.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
110 <?php if ( $cal ) { ?>
\r
111 <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
\r
112 <script src="<?php yourls_site_url(); ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
\r
114 <?php if ( $charts ) { ?>
\r
115 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
\r
116 <script type="text/javascript">
\r
117 google.load('visualization', '1.0', {'packages':['corechart', 'geochart']});
\r
120 <script type="text/javascript">
\r
122 var ajaxurl = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';
\r
123 var zclipurl = '<?php yourls_site_url(); ?>/js/ZeroClipboard.swf';
\r
126 <?php yourls_do_action( 'html_head', $context ); ?>
\r
128 <body class="<?php echo $context; ?> <?php echo $bodyclass; ?>">
\r
134 * Display HTML footer (including closing body & html tags)
\r
137 function yourls_html_footer() {
\r
140 $num_queries = sprintf( yourls_n( '1 query', '%s queries', $ydb->num_queries ), $ydb->num_queries );
\r
142 </div> <?php // wrap ?>
\r
143 <div id="footer"><p>
\r
145 $footer = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION );
\r
146 $footer .= ' – '.$num_queries;
\r
147 echo yourls_apply_filters( 'html_footer_text', $footer );
\r
150 <?php if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) {
\r
151 echo '<p>'. $ydb->all_queries .'<p>';
\r
153 <?php yourls_do_action( 'html_footer', $ydb->context ); ?>
\r
160 * Display "Add new URL" box
\r
162 * @param string $url URL to prefill the input with
\r
163 * @param string $keyword Keyword to prefill the input with
\r
165 function yourls_html_addnew( $url = '', $keyword = '' ) {
\r
166 $url = $url ? $url : 'http://';
\r
170 <form id="new_url_form" action="" method="get">
\r
171 <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
172 <?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
173 <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?>
\r
174 <input type="button" id="add-button" name="add-button" value="<?php yourls_e( 'Shorten The URL' ); ?>" class="button" onclick="add_link();" /></div>
\r
176 <div id="feedback" style="display:none"></div>
\r
178 <?php yourls_do_action( 'html_addnew' ); ?>
\r
184 * Display main table's footer
\r
186 * The $param array is defined in /admin/index.php, check the yourls_html_tfooter() call
\r
188 * @param array $params Array of all required parameters
\r
189 * @return string Result
\r
191 function yourls_html_tfooter( $params = array() ) {
\r
192 extract( $params ); // extract $search_text, $page, $search_in ...
\r
197 <div id="filter_form">
\r
198 <form action="" method="get">
\r
199 <div id="filter_options">
\r
200 <?php yourls_e( 'Search for' ); ?>
\r
201 <input type="text" name="search" class="text" size="12" value="<?php echo yourls_esc_attr( $search_text ); ?>" />
\r
202 <?php yourls_e( 'in' ); ?>
\r
203 <select name="search_in" size="1">
\r
204 <option value="keyword"<?php if( $search_in == 'keyword' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Short URL' ); ?></option>
\r
205 <option value="url"<?php if( $search_in == 'url' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'URL' ); ?></option>
\r
206 <option value="title"<?php if( $search_in == 'title' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Title' ); ?></option>
\r
207 <option value="ip"<?php if( $search_in == 'ip' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'IP' ); ?></option>
\r
209 – <?php yourls_e( 'Order by' ); ?>
\r
210 <?php $sort_by = isset( $sort_by ) ? $sort_by : 'timestamp' ; ?>
\r
211 <select name="sort_by" size="1">
\r
212 <option value="keyword"<?php if( $sort_by == 'keyword' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Short URL' ); ?></option>
\r
213 <option value="url"<?php if( $sort_by == 'url' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'URL' ); ?></option>
\r
214 <option value="timestamp"<?php if( $sort_by == 'timestamp' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Date' ); ?></option>
\r
215 <option value="ip"<?php if( $sort_by == 'ip' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'IP' ); ?></option>
\r
216 <option value="clicks"<?php if( $sort_by == 'clicks' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Clicks' ); ?></option>
\r
218 <?php $sort_order = isset( $sort_order ) ? $sort_order : 'desc' ; ?>
\r
219 <select name="sort_order" size="1">
\r
220 <option value="asc" <?php if( $sort_order == 'asc' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Ascending' ); ?></option>
\r
221 <option value="desc"<?php if( $sort_order == 'desc' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'Descending' ); ?></option>
\r
223 – <?php yourls_e( 'Show' ); ?>
\r
224 <input type="text" name="perpage" class="text" size="2" value="<?php echo $perpage; ?>" /> <?php yourls_e('rows'); ?><br/>
\r
226 <?php yourls_e( 'Show links with' ); ?>
\r
227 <select name="click_filter" size="1">
\r
228 <option value="more"<?php if( $click_filter === 'more' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'more' ); ?></option>
\r
229 <option value="less"<?php if( $click_filter === 'less' ) { echo ' selected="selected"'; } ?>><?php yourls_e( 'less' ); ?></option>
\r
231 <?php yourls_e( 'than' ); ?>
\r
232 <input type="text" name="click_limit" class="text" size="4" value="<?php echo $click_limit; ?>" /> <?php yourls_e('clicks'); ?><br/>
\r
234 <?php yourls_e( 'Show links created' ); ?>
\r
235 <select name="date_filter" id="date_filter" size="1">
\r
236 <option value="before"<?php if($date_filter === 'before') { echo ' selected="selected"'; } ?>><?php yourls_e('before'); ?></option>
\r
237 <option value="after"<?php if($date_filter === 'after') { echo ' selected="selected"'; } ?>><?php yourls_e('after'); ?></option>
\r
238 <option value="between"<?php if($date_filter === 'between') { echo ' selected="selected"'; } ?>><?php yourls_e( 'between' ); ?></option>
\r
240 <input type="text" name="date_first" id="date_first" class="text" size="12" value="<?php echo $date_first; ?>" />
\r
241 <span id="date_and" <?php if($date_filter === 'between') { echo ' style="display:inline"'; } ?>> & </span>
\r
242 <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
244 <div id="filter_buttons">
\r
245 <input type="submit" id="submit-sort" value="<?php yourls_e('Search'); ?>" class="button primary" />
\r
247 <input type="button" id="submit-clear-filter" value="<?php yourls_e('Clear'); ?>" class="button" onclick="window.parent.location.href = 'index.php'" />
\r
255 // Remove empty keys from the $params array so it doesn't clutter the pagination links
\r
256 $params = array_filter( $params, 'yourls_return_if_not_empty_string' ); // remove empty keys
\r
258 if( isset( $search_text ) ) {
\r
259 $params['search'] = $search_text;
\r
260 unset( $params['search_text'] );
\r
264 <div id="pagination">
\r
265 <span class="navigation">
\r
266 <?php if( $total_pages > 1 ) { ?>
\r
267 <span class="nav_total"><?php echo sprintf( yourls_n( '1 page', '%s pages', $total_pages ), $total_pages ); ?></span>
\r
269 $base_page = yourls_admin_url( 'index.php' );
\r
270 // Pagination offsets: min( max ( zomg! ) );
\r
271 $p_start = max( min( $total_pages - 4, $page - 2 ), 1 );
\r
272 $p_end = min( max( 5, $page + 2 ), $total_pages );
\r
273 if( $p_start >= 2 ) {
\r
274 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page );
\r
275 echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '« First' ) . '</a></span>';
\r
276 echo '<span class="nav_link nav_prev"></span>';
\r
278 for( $i = $p_start ; $i <= $p_end; $i++ ) {
\r
279 if( $i == $page ) {
\r
280 echo "<span class='nav_link nav_current'>$i</span>";
\r
282 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page );
\r
283 echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>';
\r
286 if( ( $p_end ) < $total_pages ) {
\r
287 $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page );
\r
288 echo '<span class="nav_link nav_next"></span>';
\r
289 echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( 'Last »' ) . '</a></span>';
\r
297 <?php yourls_do_action( 'html_tfooter' ); ?>
\r
303 * Display the Quick Share box
\r
306 function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) {
\r
307 if ( $shortlink_title == '' )
\r
308 $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>';
\r
309 if ( $share_title == '' )
\r
310 $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>';
\r
312 // Allow plugins to short-circuit the whole function
\r
313 $pre = yourls_apply_filter( 'shunt_share_box', false );
\r
314 if ( false !== $pre )
\r
317 $text = ( $text ? '"'.$text.'" ' : '' );
\r
318 $title = ( $title ? "$title " : '' );
\r
319 $share = yourls_esc_textarea( $title.$text.$shorturl );
\r
320 $count = 140 - strlen( $share );
\r
321 $hidden = ( $hidden ? 'style="display:none;"' : '' );
\r
323 // Allow plugins to filter all data
\r
324 $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );
\r
325 $data = yourls_apply_filter( 'share_box_data', $data );
\r
328 $_share = rawurlencode( $share );
\r
329 $_url = rawurlencode( $shorturl );
\r
332 <div id="shareboxes" <?php echo $hidden; ?>>
\r
334 <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>
\r
336 <div id="copybox" class="share">
\r
337 <?php echo $shortlink_title; ?>
\r
338 <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p>
\r
339 <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
340 <?php if( yourls_do_log_redirect() ) { ?>
\r
341 <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
342 <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" />
\r
347 <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>
\r
349 <div id="sharebox" class="share">
\r
350 <?php echo $share_title; ?>
\r
352 <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>
\r
353 <textarea id="tweet_body"><?php echo $share; ?></textarea>
\r
355 <p id="share_links"><?php yourls_e( 'Share with' ); ?>
\r
356 <a id="share_tw" href="http://twitter.com/home?status=<?php echo $_share; ?>" title="<?php yourls_e( 'Tweet this!' ); ?>" onclick="share('tw');return false">Twitter</a>
\r
357 <a id="share_fb" href="http://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e( 'Share on Facebook' ); ?>" onclick="share('fb');return false;">Facebook</a>
\r
358 <a id="share_ff" href="http://friendfeed.com/share/bookmarklet/frame#title=<?php echo $_share; ?>" title="<?php yourls_e( 'Share on Friendfeed' ); ?>" onclick="share('ff');return false;">FriendFeed</a>
\r
360 yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );
\r
361 // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.
\r
366 <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>
\r
377 function yourls_die( $message = '', $title = '', $header_code = 200 ) {
\r
378 yourls_status_header( $header_code );
\r
380 if( !yourls_did_action( 'html_head' ) ) {
\r
381 yourls_html_head();
\r
382 yourls_html_logo();
\r
384 echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" );
\r
385 echo yourls_apply_filter( 'die_message', "<p>$message</p>" );
\r
386 yourls_do_action( 'yourls_die' );
\r
387 if( !yourls_did_action( 'html_head' ) ) {
\r
388 yourls_html_footer();
\r
394 * Return an "Edit" row for the main table
\r
396 * @param string $keyword Keyword to edit
\r
397 * @return string HTML of the edit row
\r
399 function yourls_table_edit_row( $keyword ) {
\r
402 $table = YOURLS_DB_TABLE_URL;
\r
403 $keyword = yourls_sanitize_string( $keyword );
\r
404 $id = yourls_string2htmlid( $keyword ); // used as HTML #id
\r
405 $url = yourls_get_keyword_longurl( $keyword );
\r
407 $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );
\r
408 $safe_url = yourls_esc_attr( $url );
\r
409 $safe_title = yourls_esc_attr( $title );
\r
410 $www = yourls_link();
\r
412 $save_link = yourls_nonce_url( 'save-link_'.$id,
\r
413 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit_save', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
\r
416 $nonce = yourls_create_nonce( 'edit-save_'.$id );
\r
419 $return = <<<RETURN
\r
420 <tr id="edit-$id" class="edit-row"><td colspan="5" class="edit-row"><strong>%s</strong>:<input type="text" id="edit-url-$id" name="edit-url-$id" value="$safe_url" class="text" size="70" /><br/><strong>%s</strong>: $www<input type="text" id="edit-keyword-$id" name="edit-keyword-$id" value="$keyword" class="text" size="10" /><br/><strong>%s</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="%s" title="%s" class="button" onclick="edit_link_save('$id');" /> <input type="button" id="edit-close-$id" name="edit-close-$id" value="%s" title="%s" class="button" onclick="edit_link_hide('$id');" /><input type="hidden" id="old_keyword_$id" value="$keyword"/><input type="hidden" id="nonce_$id" value="$nonce"/></td></tr>
\r
422 $return = sprintf( urldecode( $return ), yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) );
\r
424 $return = '<tr class="edit-row notfound">><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>';
\r
427 $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );
\r
433 * Return an "Add" row for the main table
\r
435 * @return string HTML of the edit row
\r
437 function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) {
\r
438 $keyword = yourls_sanitize_string( $keyword );
\r
439 $id = yourls_string2htmlid( $keyword ); // used as HTML #id
\r
440 $shorturl = yourls_link( $keyword );
\r
442 $statlink = yourls_statlink( $keyword );
\r
444 $delete_link = yourls_nonce_url( 'delete-link_'.$id,
\r
445 yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
\r
448 $edit_link = yourls_nonce_url( 'edit-link_'.$id,
\r
449 yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
\r
452 // Action link buttons: the array
\r
455 'href' => $statlink,
\r
456 'id' => "statlink-$id",
\r
457 'title' => yourls_esc_attr__( 'Stats' ),
\r
458 'anchor' => yourls__( 'Stats' ),
\r
462 'id' => "share-button-$id",
\r
463 'title' => yourls_esc_attr__( 'Share' ),
\r
464 'anchor' => yourls__( 'Share' ),
\r
465 'onclick' => "toggle_share('$id');return false;",
\r
468 'href' => $edit_link,
\r
469 'id' => "edit-button-$id",
\r
470 'title' => yourls_esc_attr__( 'Edit' ),
\r
471 'anchor' => yourls__( 'Edit' ),
\r
472 'onclick' => "edit_link_display('$id');return false;",
\r
475 'href' => $delete_link,
\r
476 'id' => "delete-button-$id",
\r
477 'title' => yourls_esc_attr__( 'Delete' ),
\r
478 'anchor' => yourls__( 'Delete' ),
\r
479 'onclick' => "remove_link('$id');return false;",
\r
482 $actions = yourls_apply_filter( 'table_add_row_action_array', $actions );
\r
484 // Action link buttons: the HTML
\r
485 $action_links = '';
\r
486 foreach( $actions as $key => $action ) {
\r
487 $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;
\r
488 $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',
\r
489 $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']
\r
492 $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );
\r
497 $protocol_warning = '';
\r
498 if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) )
\r
499 $protocol_warning = yourls_apply_filters( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' );
\r
501 // Row cells: the array
\r
503 'keyword' => array(
\r
504 'template' => '<a href="%shorturl%">%keyword_html%</a>',
\r
505 'shorturl' => yourls_esc_url( $shorturl ),
\r
506 'keyword_html' => yourls_esc_html( $keyword ),
\r
509 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>',
\r
510 'long_url' => yourls_esc_url( $url ),
\r
511 'title_attr' => yourls_esc_attr( $title ),
\r
512 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ),
\r
513 'long_url_html' => yourls_esc_html( yourls_trim_long_string( $url ) ),
\r
514 'warning' => $protocol_warning,
\r
516 'timestamp' => array(
\r
517 'template' => '%date%',
\r
518 'date' => date( 'M d, Y H:i', $timestamp +( YOURLS_HOURS_OFFSET * 3600 ) ),
\r
521 'template' => '%ip%',
\r
525 'template' => '%clicks%',
\r
526 'clicks' => yourls_number_format_i18n( $clicks, 0, '', '' ),
\r
528 'actions' => array(
\r
529 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>',
\r
530 'actions' => $action_links,
\r
532 'keyword' => $keyword,
\r
535 $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp );
\r
537 // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value.
\r
538 $row = "<tr id=\"id-$id\">";
\r
539 foreach( $cells as $cell_id => $elements ) {
\r
540 $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id );
\r
541 $row .= preg_replace( '/%([^%]+)?%/e', '$elements["$1"]', $elements['template'] );
\r
545 $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );
\r
551 * Echo the main table head
\r
554 function yourls_table_head() {
\r
555 $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";
\r
556 echo yourls_apply_filter( 'table_head_start', $start );
\r
558 $cells = yourls_apply_filter( 'table_head_cells', array(
\r
559 'shorturl' => yourls__( 'Short URL' ),
\r
560 'longurl' => yourls__( 'Original URL' ),
\r
561 'date' => yourls__( 'Date' ),
\r
562 'ip' => yourls__( 'IP' ),
\r
563 'clicks' => yourls__( 'Clicks' ),
\r
564 'actions' => yourls__( 'Actions' )
\r
566 foreach( $cells as $k => $v ) {
\r
567 echo "<th id='main_table_head_$k'>$v</th>\n";
\r
570 $end = "</tr></thead>\n";
\r
571 echo yourls_apply_filter( 'table_head_end', $end );
\r
575 * Echo the tbody start tag
\r
578 function yourls_table_tbody_start() {
\r
579 echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );
\r
583 * Echo the tbody end tag
\r
586 function yourls_table_tbody_end() {
\r
587 echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );
\r
591 * Echo the table start tag
\r
594 function yourls_table_end() {
\r
595 echo yourls_apply_filter( 'table_end', '</table>' );
\r
599 * Echo HTML tag for a link
\r
602 function yourls_html_link( $href, $title = '', $element = '' ) {
\r
606 $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) );
\r
607 $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) );
\r
608 echo yourls_apply_filter( 'html_link', $link );
\r
612 * Display the login screen. Nothing past this point.
\r
615 function yourls_login_screen( $error_msg = '' ) {
\r
616 yourls_html_head( 'login' );
\r
618 $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' );
\r
620 yourls_html_logo();
\r
623 <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>
\r
625 if( !empty( $error_msg ) ) {
\r
626 echo '<p class="error">'.$error_msg.'</p>';
\r
630 <label for="username"><?php yourls_e( 'Username' ); ?></label><br />
\r
631 <input type="text" id="username" name="username" size="30" class="text" />
\r
634 <label for="password"><?php yourls_e( 'Password' ); ?></label><br />
\r
635 <input type="password" id="password" name="password" size="30" class="text" />
\r
637 <p style="text-align: right;">
\r
638 <input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" />
\r
641 <script type="text/javascript">$('#username').focus();</script>
\r
644 yourls_html_footer();
\r
649 * Display the admin menu
\r
652 function yourls_html_menu() {
\r
654 // Build menu links
\r
655 if( defined( 'YOURLS_USER' ) ) {
\r
656 $logout_link = yourls_apply_filter( 'logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' </strong> (<a href="?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' );
\r
658 $logout_link = yourls_apply_filter( 'logout_link', '' );
\r
660 $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' );
\r
662 $admin_links = array();
\r
663 $admin_sublinks = array();
\r
665 $admin_links['admin'] = array(
\r
666 'url' => yourls_admin_url( 'index.php' ),
\r
667 'title' => yourls__( 'Go to the admin interface' ),
\r
668 'anchor' => yourls__( 'Admin interface' )
\r
671 if( yourls_is_admin() ) {
\r
672 $admin_links['tools'] = array(
\r
673 'url' => yourls_admin_url( 'tools.php' ),
\r
674 'anchor' => yourls__( 'Tools' )
\r
676 $admin_links['plugins'] = array(
\r
677 'url' => yourls_admin_url( 'plugins.php' ),
\r
678 'anchor' => yourls__( 'Manage Plugins' )
\r
680 $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages();
\r
683 $admin_links = yourls_apply_filter( 'admin_links', $admin_links );
\r
684 $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks );
\r
687 echo '<ul id="admin_menu">'."\n";
\r
688 if ( yourls_is_private() && !empty( $logout_link ) )
\r
689 echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>';
\r
691 foreach( (array)$admin_links as $link => $ar ) {
\r
692 if( isset( $ar['url'] ) ) {
\r
693 $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
\r
694 $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
\r
695 printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor );
\r
697 // Output submenu if any. TODO: clean up, too many code duplicated here
\r
698 if( isset( $admin_sublinks[$link] ) ) {
\r
700 foreach( $admin_sublinks[$link] as $link => $ar ) {
\r
701 if( isset( $ar['url'] ) ) {
\r
702 $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
\r
703 $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
\r
704 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
711 if ( isset( $help_link ) )
\r
712 echo '<li id="admin_menu_help_link">' . $help_link .'</li>';
\r
714 yourls_do_action( 'admin_menu' );
\r
716 yourls_do_action( 'admin_notices' );
\r
717 yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'
\r
719 To display a notice:
\r
720 $message = "<div>OMG, dude, I mean!</div>" );
\r
721 yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );
\r
726 * Wrapper function to display admin notices
\r
729 function yourls_add_notice( $message, $style = 'notice' ) {
\r
730 $message = yourls_notice_box( $message, $style );
\r
731 yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );
\r
735 * Return a formatted notice
\r
738 function yourls_notice_box( $message, $style = 'notice' ) {
\r
740 <div class="$style">
\r
750 function yourls_page( $page ) {
\r
751 $include = YOURLS_ABSPATH . "/pages/$page.php";
\r
752 if( !file_exists($include) ) {
\r
753 yourls_die( "Page '$page' not found", 'Not found', 404 );
\r
755 yourls_do_action( 'pre_page', $page );
\r
757 yourls_do_action( 'post_page', $page );
\r