2 define( 'YOURLS_ADMIN', true );
\r
3 require_once( dirname( dirname( __FILE__ ) ).'/includes/load-yourls.php' );
\r
4 yourls_maybe_require_auth();
\r
7 $table_url = YOURLS_DB_TABLE_URL;
\r
8 $where = $search_sentence = $search_text = $url = $keyword = '';
\r
9 $date_filter = $date_first = $date_second = '';
\r
10 $base_page = yourls_admin_url( 'index.php' );
\r
12 // Default SQL behavior
\r
13 $search_in_text = yourls__( 'URL' );
\r
15 $sort_by_text = yourls__( 'Short URL' );
\r
16 $sort_by = 'timestamp';
\r
17 $sort_order = 'desc';
\r
18 $page = ( isset( $_GET['page'] ) ? intval($_GET['page']) : 1 );
\r
19 $search = ( isset( $_GET['search'] ) ? htmlspecialchars( trim($_GET['search']) ) : '' );
\r
20 $perpage = ( isset( $_GET['perpage'] ) && intval( $_GET['perpage'] ) ? intval($_GET['perpage']) : 15 );
\r
21 $click_limit = ( isset( $_GET['click_limit'] ) && $_GET['click_limit'] !== '' ) ? intval( $_GET['click_limit'] ) : '' ;
\r
22 if ( $click_limit !== '' ) {
\r
23 $click_filter = ( isset( $_GET['click_filter'] ) && $_GET['click_filter'] == 'more' ? 'more' : 'less' ) ;
\r
24 $click_moreless = ( $click_filter == 'more' ? '>' : '<' );
\r
25 $where = " AND clicks $click_moreless $click_limit";
\r
31 if( !empty( $search ) && !empty( $_GET['search_in'] ) ) {
\r
32 switch( $_GET['search_in'] ) {
\r
34 $search_in_text = yourls__( 'Short URL' );
\r
35 $search_in = 'keyword';
\r
38 $search_in_text = yourls__( 'URL' );
\r
42 $search_in_text = yourls__( 'Title' );
\r
43 $search_in = 'title';
\r
46 $search_in_text = yourls__( 'IP Address' );
\r
50 $search_sentence = yourls_s( 'Searching for <strong>%1$s</strong> in <strong>%2$s</strong>.', yourls_esc_html( $search ), yourls_esc_html( $search_in_text ) );
\r
51 $search_url = yourls_sanitize_url( "&search=$search&search_in=$search_in" );
\r
52 $search_text = $search;
\r
53 $search = str_replace( '*', '%', '*' . yourls_escape( $search ) . '*' );
\r
54 $where .= " AND `$search_in` LIKE ('$search')";
\r
58 if( !empty( $_GET['date_filter'] ) ) {
\r
59 switch( $_GET['date_filter'] ) {
\r
61 $date_filter = 'before';
\r
62 if( isset( $_GET['date_first'] ) && yourls_sanitize_date( $_GET['date_first'] ) ) {
\r
63 $date_first = yourls_sanitize_date( $_GET['date_first'] );
\r
64 $date_first_sql = yourls_sanitize_date_for_sql( $_GET['date_first'] );
\r
65 $where .= " AND `timestamp` < '$date_first_sql'";
\r
69 $date_filter = 'after';
\r
70 if( isset( $_GET['date_first'] ) && yourls_sanitize_date( $_GET['date_first'] ) ) {
\r
71 $date_first_sql = yourls_sanitize_date_for_sql( $_GET['date_first'] );
\r
72 $date_first = yourls_sanitize_date( $_GET['date_first'] );
\r
73 $where .= " AND `timestamp` > '$date_first_sql'";
\r
77 $date_filter = 'between';
\r
78 if( isset( $_GET['date_first'] ) && isset( $_GET['date_second'] ) && yourls_sanitize_date( $_GET['date_first'] ) && yourls_sanitize_date( $_GET['date_second'] ) ) {
\r
79 $date_first_sql = yourls_sanitize_date_for_sql( $_GET['date_first'] );
\r
80 $date_second_sql = yourls_sanitize_date_for_sql( $_GET['date_second'] );
\r
81 $date_first = yourls_sanitize_date( $_GET['date_first'] );
\r
82 $date_second = yourls_sanitize_date( $_GET['date_second'] );
\r
83 $where .= " AND `timestamp` BETWEEN '$date_first_sql' AND '$date_second_sql'";
\r
90 if( !empty( $_GET['sort_by'] ) || !empty( $_GET['sort_order'] ) ) {
\r
91 switch( $_GET['sort_by'] ) {
\r
93 $sort_by_text = yourls__( 'Short URL' );
\r
94 $sort_by = 'keyword';
\r
97 $sort_by_text = yourls__( 'URL' );
\r
101 $sort_by_text = yourls__( 'Date' );
\r
102 $sort_by = 'timestamp';
\r
105 $sort_by_text = yourls__( 'IP Address' );
\r
109 $sort_by_text = yourls__( 'Clicks' );
\r
110 $sort_by = 'clicks';
\r
113 switch( $_GET['sort_order'] ) {
\r
115 $sort_order = 'asc';
\r
118 $sort_order = 'desc';
\r
123 // Get URLs Count for current filter, total links in DB & total clicks
\r
124 list( $total_urls, $total_clicks ) = array_values( yourls_get_db_stats() );
\r
126 list( $total_items, $total_items_clicks ) = array_values( yourls_get_db_stats( $where ) );
\r
128 $total_items = $total_urls;
\r
129 $total_items_clicks = false;
\r
132 // This is a bookmarklet
\r
133 if ( isset( $_GET['u'] ) ) {
\r
134 $is_bookmark = true;
\r
135 yourls_do_action( 'bookmarklet' );
\r
137 // No sanitization needed here: everything happens in yourls_add_new_link()
\r
138 $url = ( $_GET['u'] );
\r
139 $keyword = ( isset( $_GET['k'] ) ? ( $_GET['k'] ) : '' );
\r
140 $title = ( isset( $_GET['t'] ) ? ( $_GET['t'] ) : '' );
\r
141 $return = yourls_add_new_link( $url, $keyword, $title );
\r
143 // If fails because keyword already exist, retry with no keyword
\r
144 if ( isset( $return['status'] ) && $return['status'] == 'fail' && isset( $return['code'] ) && $return['code'] == 'error:keyword' ) {
\r
145 $msg = $return['message'];
\r
146 $return = yourls_add_new_link( $url, '', $ydb );
\r
147 $return['message'] .= ' ('.$msg.')';
\r
150 // Stop here if bookmarklet with a JSON callback function
\r
151 if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) {
\r
152 $short = $return['shorturl'] ? $return['shorturl'] : '';
\r
153 $message = $return['message'];
\r
154 header( 'Content-type: application/json' );
\r
155 echo yourls_apply_filter( 'bookmarklet_jsonp', "yourls_callback({'short_url':'$short','message':'$message'});" );
\r
160 // Now use the URL that has been sanitized and returned by yourls_add_new_link()
\r
161 $url = $return['url']['url'];
\r
162 $where = sprintf( " AND `url` LIKE '%s' ", yourls_escape( $url ) );
\r
164 $page = $total_pages = $perpage = 1;
\r
167 $text = ( isset( $_GET['s'] ) ? stripslashes( $_GET['s'] ) : '' );
\r
170 // This is not a bookmarklet
\r
172 $is_bookmark = false;
\r
174 // Checking $page, $offset, $perpage
\r
175 if( empty($page) || $page == 0 ) {
\r
178 if( empty($offset) ) {
\r
181 if( empty($perpage) || $perpage == 0) {
\r
185 // Determine $offset
\r
186 $offset = ( $page-1 ) * $perpage;
\r
188 // Determine Max Number Of Items To Display On Page
\r
189 if( ( $offset + $perpage ) > $total_items ) {
\r
190 $max_on_page = $total_items;
\r
192 $max_on_page = ( $offset + $perpage );
\r
195 // Determine Number Of Items To Display On Page
\r
196 if ( ( $offset + 1 ) > $total_items ) {
\r
197 $display_on_page = $total_items;
\r
199 $display_on_page = ( $offset + 1 );
\r
202 // Determing Total Amount Of Pages
\r
203 $total_pages = ceil( $total_items / $perpage );
\r
207 // Begin output of the page
\r
208 $context = ( $is_bookmark ? 'bookmark' : 'index' );
\r
209 yourls_html_head( $context );
\r
210 yourls_html_logo();
\r
211 yourls_html_menu() ;
\r
213 yourls_do_action( 'admin_page_before_content' );
\r
215 if ( !$is_bookmark ) { ?>
\r
216 <p><?php echo $search_sentence; ?></p>
\r
218 printf( yourls__( 'Display <strong>%1$s</strong> to <strong class="increment">%2$s</strong> of <strong class="increment">%3$s</strong> URLs' ), $display_on_page, $max_on_page, $total_items );
\r
219 if( $total_items_clicks !== false )
\r
220 echo ", " . sprintf( yourls_n( 'counting <strong>1</strong> click', 'counting <strong>%s</strong> clicks', $total_items_clicks ), yourls_number_format_i18n( $total_items_clicks ) );
\r
223 <p><?php printf( yourls__( 'Overall, tracking <strong class="increment">%1$s</strong> links, <strong>%2$s</strong> clicks, and counting!' ), yourls_number_format_i18n( $total_urls ), yourls_number_format_i18n( $total_clicks ) ); ?></p>
\r
224 <?php yourls_do_action( 'admin_page_before_form' ); ?>
\r
226 <?php yourls_html_addnew(); ?>
\r
229 // If bookmarklet, add message. Otherwise, hide hidden share box.
\r
230 if ( !$is_bookmark ) {
\r
231 yourls_share_box( '', '', '', '', '', '', true );
\r
233 echo '<script type="text/javascript">$(document).ready(function(){
\r
234 feedback( "' . $return['message'] . '", "'. $return['status'] .'");
\r
239 yourls_do_action( 'admin_page_before_table' );
\r
241 yourls_table_head();
\r
243 if ( !$is_bookmark ) {
\r
245 'search' => $search,
\r
246 'search_text' => $search_text,
\r
247 'search_in' => $search_in,
\r
248 'sort_by' => $sort_by,
\r
249 'sort_order' => $sort_order,
\r
251 'perpage' => $perpage,
\r
252 'click_filter' => $click_filter,
\r
253 'click_limit' => $click_limit,
\r
254 'total_pages' => $total_pages,
\r
255 'date_filter' => $date_filter,
\r
256 'date_first' => $date_first,
\r
257 'date_second' => $date_second,
\r
259 yourls_html_tfooter( $params );
\r
262 yourls_table_tbody_start();
\r
265 $where = yourls_apply_filter( 'admin_list_where', $where );
\r
266 $url_results = $ydb->get_results( "SELECT * FROM `$table_url` WHERE 1=1 $where ORDER BY `$sort_by` $sort_order LIMIT $offset, $perpage;" );
\r
267 $found_rows = false;
\r
268 if( $url_results ) {
\r
269 $found_rows = true;
\r
270 foreach( $url_results as $url_result ) {
\r
271 $keyword = yourls_sanitize_string( $url_result->keyword );
\r
272 $timestamp = strtotime( $url_result->timestamp );
\r
273 $url = stripslashes( $url_result->url );
\r
274 $ip = $url_result->ip;
\r
275 $title = $url_result->title ? $url_result->title : '';
\r
276 $clicks = $url_result->clicks;
\r
278 echo yourls_table_add_row( $keyword, $url, $title, $ip, $clicks, $timestamp );
\r
282 $display = $found_rows ? 'display:none' : '';
\r
283 echo '<tr id="nourl_found" style="'.$display.'"><td colspan="6">' . yourls__('No URL') . '</td></tr>';
\r
285 yourls_table_tbody_end();
\r
287 yourls_table_end();
\r
289 yourls_do_action( 'admin_page_after_table' );
\r
291 if ( $is_bookmark )
\r
292 yourls_share_box( $url, $return['shorturl'], $title, $text );
\r
295 <?php yourls_html_footer( ); ?>