yourls_html_head()   F
last analyzed

Complexity

Conditions 20
Paths 5120

Size

Total Lines 102
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 40.492

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 20
eloc 80
c 4
b 0
f 1
nc 5120
nop 2
dl 0
loc 102
ccs 22
cts 35
cp 0.6286
crap 40.492
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Display <h1> header and logo
5
 *
6
 */
7
function yourls_html_logo() {
8 1
	yourls_do_action( 'pre_html_logo' );
9
	?>
10 1
	<header role="banner">
11
	<h1>
12
		<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/>
0 ignored issues
show
Coding Style introduced by
Inline PHP statement must end with a semicolon
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 173 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
13
		<img src="<?php yourls_site_url(); ?>/images/yourls-logo.svg" id="yourls-logo" alt="YOURLS" title="YOURLS" /></a>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 115 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
14
	</h1>
15
	</header>
16
	<?php
17 1
	yourls_do_action( 'html_logo' );
18 1
}
19
20
/**
21
 * Display HTML head and <body> tag
22
 *
23
 * @param string $context Context of the page (stats, index, infos, ...)
24
 * @param string $title HTML title of the page
25
 */
26
function yourls_html_head( $context = 'index', $title = '' ) {
27
28 1
	yourls_do_action( 'pre_html_head', $context, $title );
29
30
	// All components to false, except when specified true
31 1
	$share = $insert = $tablesorter = $tabs = $cal = $charts = false;
32
33
	// Load components as needed
34 1
	switch ( $context ) {
35 1
		case 'infos':
36
			$share = $tabs = $charts = true;
37
			break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 6 spaces, found 3
Loading history...
38
39 1
		case 'bookmark':
40
			$share = $insert = $tablesorter = true;
41
			break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 6 spaces, found 3
Loading history...
42
43 1
		case 'index':
44
			$insert = $tablesorter = $cal = $share = true;
45
			break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 6 spaces, found 3
Loading history...
46
47 1
		case 'plugins':
48 1
		case 'tools':
49
			$tablesorter = true;
50
			break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 6 spaces, found 3
Loading history...
51
52 1
		case 'install':
53 1
		case 'login':
54 1
		case 'new':
55 1
		case 'upgrade':
56
			break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 6 spaces, found 3
Loading history...
57
	}
58
59
	// Force no cache for all admin pages
60 1
	if( yourls_is_admin() && !headers_sent() ) {
61
        yourls_no_cache_headers();
62
		yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) );
63
		yourls_do_action( 'admin_headers', $context, $title );
64
	}
65
66
	// Store page context
67 1
	yourls_set_html_context($context);
68
69
	// Body class
70 1
	$bodyclass = yourls_apply_filter( 'bodyclass', '' );
71 1
	$bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' );
72
73
	// Page title
74 1
	$_title = 'YOURLS &mdash; Your Own URL Shortener | ' . yourls_link();
75 1
	$title = $title ? $title . " &laquo; " . $_title : $_title;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal « does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
76 1
	$title = yourls_apply_filter( 'html_title', $title, $context );
77
0 ignored issues
show
Coding Style introduced by
Blank line found at end of embedded PHP content
Loading history...
78
	?>
79 1
<!DOCTYPE html>
80
<html <?php yourls_html_language_attributes(); ?>>
81
<head>
82
	<title><?php echo $title ?></title>
0 ignored issues
show
Coding Style introduced by
Inline PHP statement must end with a semicolon
Loading history...
83
	<meta http-equiv="Content-Type" content="<?php echo yourls_apply_filter( 'html_head_meta_content-type', 'text/html; charset=utf-8' ); ?>" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
84
	<meta name="generator" content="YOURLS <?php echo YOURLS_VERSION ?>" />
0 ignored issues
show
Coding Style introduced by
Inline PHP statement must end with a semicolon
Loading history...
85
	<meta name="description" content="YOURLS &raquo; Your Own URL Shortener' | <?php yourls_site_url(); ?>" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
86
	<?php yourls_do_action('html_head_meta', $context); ?>
87
	<link rel="shortcut icon" href="<?php yourls_get_yourls_favicon_url(); ?>" />
88
	<script src="<?php yourls_site_url(); ?>/js/jquery-3.5.1.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
89
	<script src="<?php yourls_site_url(); ?>/js/common.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 120 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
90
	<script src="<?php yourls_site_url(); ?>/js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
91
	<link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
92
	<?php if ( $tabs ) { ?>
93
		<link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
94
		<script src="<?php yourls_site_url(); ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 120 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
95
	<?php } ?>
96
	<?php if ( $tablesorter ) { ?>
97
		<link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
98
		<script src="<?php yourls_site_url(); ?>/js/jquery-3.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
99
		<script src="<?php yourls_site_url(); ?>/js/tablesorte.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
100
	<?php } ?>
101
	<?php if ( $insert ) { ?>
102
		<script src="<?php yourls_site_url(); ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
103
	<?php } ?>
104
	<?php if ( $share ) { ?>
105
		<link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
106
		<script src="<?php yourls_site_url(); ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 120 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
107
		<script src="<?php yourls_site_url(); ?>/js/clipboard.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
108
	<?php } ?>
109
	<?php if ( $cal ) { ?>
110
		<link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
111
		<?php yourls_l10n_calendar_strings(); ?>
112
		<script src="<?php yourls_site_url(); ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
113
	<?php } ?>
114
	<?php if ( $charts ) { ?>
115
			<script type="text/javascript" src="https://www.google.com/jsapi"></script>
116
			<script type="text/javascript">
117
					 google.load('visualization', '1.0', {'packages':['corechart', 'geochart']});
118
			</script>
119
	<?php } ?>
120 1
	<script type="text/javascript">
121
	//<![CDATA[
122
		var ajaxurl  = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';
123
	//]]>
124
	</script>
125
	<?php yourls_do_action( 'html_head', $context ); ?>
126 1
</head>
127
<body class="<?php echo $context; ?> <?php echo $bodyclass; ?>">
128
<div id="wrap">
129
	<?php
130 1
}
131
132
/**
133
 * Display HTML footer (including closing body & html tags)
134
 *
135
 * Function yourls_die() will call this function with the optional param set to false: most likely, if we're using yourls_die(),
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
136
 * there's a problem, so don't maybe add to it by sending another SQL query
137
 *
138
 * @param  bool $can_query  If set to false, will not try to send another query to DB server
139
 * @return void
140
 */
141
function yourls_html_footer($can_query = true) {
142 1
    if($can_query & yourls_get_debug_mode()) {
0 ignored issues
show
Bug introduced by
Are you sure you want to use the bitwise & or did you mean &&?
Loading history...
143 1
        $num_queries = yourls_get_num_queries();
144 1
        $num_queries = ' &ndash; '. sprintf( yourls_n( '1 query', '%s queries', $num_queries ), $num_queries );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 111 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
145
    } else {
146
        $num_queries = '';
147
    }
148
149
	?>
150
	</div><?php // wrap ?>
151 1
	<footer id="footer" role="contentinfo"><p>
152
		<?php
153 1
		$footer  = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
154 1
		$footer .= $num_queries;
155 1
		echo yourls_apply_filter( 'html_footer_text', $footer );
156
		?>
157 1
	</p></footer>
158
	<?php if( yourls_get_debug_mode() ) {
0 ignored issues
show
Coding Style introduced by
Opening PHP tag must be on a line by itself
Loading history...
159 1
		echo '<div style="text-align:left"><pre>';
160 1
		echo join( "\n", yourls_get_debug_log() );
161 1
		echo '</pre></div>';
162
	} ?>
0 ignored issues
show
Coding Style introduced by
Closing PHP tag must be on a line by itself
Loading history...
163
	<?php yourls_do_action( 'html_footer', yourls_get_html_context() ); ?>
164 1
	</body>
165
	</html>
166
	<?php
167 1
}
168
169
/**
170
 * Display "Add new URL" box
171
 *
172
 * @param string $url URL to prefill the input with
173
 * @param string $keyword Keyword to prefill the input with
174
 */
175
function yourls_html_addnew( $url = '', $keyword = '' ) {
176
    $pre = yourls_apply_filter( 'shunt_html_addnew', false, $url, $keyword );
177
    if ( false !== $pre ) {
178
        return $pre;
179
    }
180
	?>
181
	<main role="main">
182
	<div id="new_url">
183
		<div>
184
			<form id="new_url_form" action="" method="get">
185
				<div>
186
                    <label for="add-url"><strong><?php yourls_e( 'Enter the URL' ); ?></strong></label>:
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
187
                    <input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" placeholder="https://" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
188
                    <label for="add-keyword"><?php yourls_e( 'Optional '); ?> : <strong><?php yourls_e('Custom short URL'); ?></strong></label>:
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
189
                    <input type="text" id="add-keyword" name="keyword" value="<?php echo $keyword; ?>" class="text" size="8" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
190
                    <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?>
191
                    <input type="button" id="add-button" name="add-button" value="<?php yourls_e( 'Shorten The URL' ); ?>" class="button" onclick="add_link();" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 162 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
192
                </div>
193
			</form>
194
			<div id="feedback" style="display:none"></div>
195
		</div>
196
		<?php yourls_do_action( 'html_addnew' ); ?>
197
	</div>
198
	<?php
199
}
200
201
/**
202
 * Display main table's footer
203
 *
204
 * The $param array is defined in /admin/index.php, check the yourls_html_tfooter() call
205
 *
206
 * @param array $params Array of all required parameters
207
 * @return string Result
208
 */
209
function yourls_html_tfooter( $params = array() ) {
210
    // Manually extract all parameters from the array. We prefer doing it this way, over using extract(),
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 105 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
211
    // to make things clearer and more explicit about what var is used.
212
    $search       = $params['search'];
0 ignored issues
show
Unused Code introduced by
The assignment to $search is dead and can be removed.
Loading history...
213
    $search_text  = $params['search_text'];
214
    $search_in    = $params['search_in'];
215
    $sort_by      = $params['sort_by'];
216
    $sort_order   = $params['sort_order'];
217
    $page         = $params['page'];
218
    $perpage      = $params['perpage'];
219
    $click_filter = $params['click_filter'];
220
    $click_limit  = $params['click_limit'];
221
    $total_pages  = $params['total_pages'];
222
    $date_filter  = $params['date_filter'];
223
    $date_first   = $params['date_first'];
224
    $date_second  = $params['date_second'];
225
0 ignored issues
show
Coding Style introduced by
Blank line found at end of embedded PHP content
Loading history...
226
	?>
227
	<tfoot>
228
		<tr>
229
			<th colspan="6">
230
			<div id="filter_form">
231
				<form action="" method="get">
232
					<div id="filter_options">
233
						<?php
234
0 ignored issues
show
Coding Style introduced by
Blank line found at start of embedded PHP content
Loading history...
235
						// First search control: text to search
236
						$_input = '<input aria-label="' .yourls__( 'Search for' ). '" type="text" name="search" class="text" size="12" value="' . yourls_esc_attr( $search_text ) . '" />';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 169 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
237
						$_options = array(
238
                            'all'     => yourls__( 'All fields' ),
239
							'keyword' => yourls__( 'Short URL' ),
240
							'url'     => yourls__( 'URL' ),
241
							'title'   => yourls__( 'Title' ),
242
							'ip'      => yourls__( 'IP' ),
243
						);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 18 space(s), but found 6.
Loading history...
244
						$_select = yourls_html_select( 'search_in', $_options, $search_in, false, yourls__( 'Search in' ) );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 106 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
245
						/* //translators: "Search for <input field with text to search> in <select dropdown with URL, title...>" */
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 113 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Coding Style introduced by
Single line block comment not allowed; use inline ("// text") comment instead
Loading history...
246
						yourls_se( 'Search for %1$s in %2$s', $_input , $_select );
247
						echo "&ndash;\n";
248
249
						// Second search control: order by
250
						$_options = array(
251
							'keyword'      => yourls__( 'Short URL' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 3 space(s) but found 6
Loading history...
252
							'url'          => yourls__( 'URL' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 7 space(s) but found 10
Loading history...
253
							'title'        => yourls__( 'Title' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 5 space(s) but found 8
Loading history...
254
							'timestamp'    => yourls__( 'Date' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 1 space(s) but found 4
Loading history...
255
							'ip'           => yourls__( 'IP' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 8 space(s) but found 11
Loading history...
256
							'clicks'       => yourls__( 'Clicks' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 7
Loading history...
257
						);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 18 space(s), but found 6.
Loading history...
258
						$_select = yourls_html_select( 'sort_by', $_options, $sort_by, false,  yourls__( 'Sort by' ) );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 101 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
259
						$sort_order = isset( $sort_order ) ? $sort_order : 'desc' ;
0 ignored issues
show
Coding Style introduced by
Space found before semicolon; expected "'desc';" but found "'desc' ;"
Loading history...
260
						$_options = array(
261
							'asc'  => yourls__( 'Ascending' ),
262
							'desc' => yourls__( 'Descending' ),
263
						);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 18 space(s), but found 6.
Loading history...
264
						$_select2 = yourls_html_select( 'sort_order', $_options, $sort_order, false,  yourls__( 'Sort order' ) );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 111 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
265
						/* //translators: "Order by <criteria dropdown (date, clicks...)> in <order dropdown (Descending or Ascending)>" */
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Coding Style introduced by
Single line block comment not allowed; use inline ("// text") comment instead
Loading history...
266
						yourls_se( 'Order by %1$s %2$s', $_select , $_select2 );
267
						echo "&ndash;\n";
268
269
						// Third search control: Show XX rows
270
						/* //translators: "Show <text field> rows" */
0 ignored issues
show
Coding Style introduced by
Single line block comment not allowed; use inline ("// text") comment instead
Loading history...
271
                        $_input = '<input aria-label="' .yourls__( 'Number of rows to show' ). '" type="text" name="perpage" class="text" size="2" value="' . $perpage . '" />';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 176 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
272
						yourls_se( 'Show %s rows',  $_input );
273
						echo "<br/>\n";
274
275
						// Fourth search control: Show links with more than XX clicks
276
						$_options = array(
277
							'more' => yourls__( 'more' ),
278
							'less' => yourls__( 'less' ),
279
						);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 18 space(s), but found 6.
Loading history...
280
						$_select = yourls_html_select( 'click_filter', $_options, $click_filter, false, yourls__( 'Show links with' ) );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 118 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
281
						$_input  = '<input aria-label="' .yourls__( 'Number of clicks' ). '" type="text" name="click_limit" class="text" size="4" value="' . $click_limit . '" /> ';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 162 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
282
						/* //translators: "Show links with <more/less> than <text field> clicks" */
0 ignored issues
show
Coding Style introduced by
Single line block comment not allowed; use inline ("// text") comment instead
Loading history...
283
						yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input );
284
						echo "<br/>\n";
285
286
						// Fifth search control: Show links created before/after/between ...
287
						$_options = array(
288
							'before'  => yourls__('before'),
289
							'after'   => yourls__('after'),
290
							'between' => yourls__('between'),
291
						);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 18 space(s), but found 6.
Loading history...
292
						$_select = yourls_html_select( 'date_filter', $_options, $date_filter, false, yourls__('Show links created') );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
293
						$_input  = '<input aria-label="' .yourls__('Select a date') . '" type="text" name="date_first" id="date_first" class="text" size="12" value="' . $date_first . '" />';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 172 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
294
						$_and    = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> &amp; </span>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
295
						$_input2 = '<input aria-label="' .yourls__('Select an end date') . '" type="text" name="date_second" id="date_second" class="text" size="12" value="' . $date_second . '"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '/>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 250 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
296
						/* //translators: "Show links created <before/after/between> <date input> <"and" if applicable> <date input if applicable>" */
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Coding Style introduced by
Single line block comment not allowed; use inline ("// text") comment instead
Loading history...
297
						yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 );
298
						?>
299
300
						<div id="filter_buttons">
301
							<input type="submit" id="submit-sort" value="<?php yourls_e('Search'); ?>" class="button primary" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
302
							&nbsp;
303
							<input type="button" id="submit-clear-filter" value="<?php yourls_e('Clear'); ?>" class="button" onclick="window.parent.location.href = 'index.php'" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 158 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
304
						</div>
305
306
					</div>
307
				</form>
308
			</div>
309
310
			<?php
311
			// Remove empty keys from the $params array so it doesn't clutter the pagination links
312
			$params = array_filter( $params, 'yourls_return_if_not_empty_string' ); // remove empty keys
313
314
			if( isset( $search_text ) ) {
315
				$params['search'] = $search_text;
316
				unset( $params['search_text'] );
317
			}
318
			?>
319
320
			<div id="pagination">
321
				<span class="navigation">
322
				<?php if( $total_pages > 1 ) { ?>
323
					<span class="nav_total"><?php echo sprintf( yourls_n( '1 page', '%s pages', $total_pages ), $total_pages ); ?></span>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
324
					<?php
325
					$base_page = yourls_admin_url( 'index.php' );
326
					// Pagination offsets: min( max ( zomg! ) );
327
					$p_start = max(  min( $total_pages - 4, $page - 2 ), 1 );
328
					$p_end = min( max( 5, $page + 2 ), $total_pages );
329
					if( $p_start >= 2 ) {
330
						$link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page );
331
						echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '&laquo; First' ) . '</a></span>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 171 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
332
						echo '<span class="nav_link nav_prev"></span>';
333
					}
334
					for( $i = $p_start ; $i <= $p_end; $i++ ) {
0 ignored issues
show
Coding Style introduced by
Space found before semicolon; expected "$p_start;" but found "$p_start ;"
Loading history...
335
						if( $i == $page ) {
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
336
							echo "<span class='nav_link nav_current'>$i</span>";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $i instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
337
						} else {
338
							$link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page );
339
							echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 147 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
340
						}
341
					}
342
					if( ( $p_end ) < $total_pages ) {
343
						$link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 106 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
344
						echo '<span class="nav_link nav_next"></span>';
345
						echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to Last Page') . '">' . yourls__( 'Last &raquo;' ) . '</a></span>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 168 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
346
					}
347
					?>
348
				<?php } ?>
349
				</span>
350
			</div>
351
			</th>
352
		</tr>
353
		<?php yourls_do_action( 'html_tfooter' ); ?>
354
	</tfoot>
355
	<?php
356
}
357
358
/**
359
 * Return or display a select dropdown field
360
 *
361
 * @since 1.6
362
 *
363
 * @param  string  $name      HTML 'name' (also use as the HTML 'id')
364
 * @param  array   $options   array of 'value' => 'Text displayed'
365
 * @param  string  $selected  optional 'value' from the $options array that will be highlighted
366
 * @param  boolean $display   false (default) to return, true to echo
367
 * @param  string  $label     ARIA label of the element
368
 * @return string HTML content of the select element
369
 */
370
function yourls_html_select( $name, $options, $selected = '', $display = false, $label = '' ) {
371
	$html = "<select aria-label='$label' name='$name' id='$name' size='1'>\n";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $label instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $name instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
372
	foreach( $options as $value => $text ) {
373
		$html .= "<option value='$value' ";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $value instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
374
		$html .= $selected == $value ? ' selected="selected"' : '';
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
375
		$html .= ">$text</option>\n";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $text instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
376
	}
377
	$html .= "</select>\n";
378
	$html  = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display );
379
	if( $display )
380
		echo $html;
381
	return $html;
382
}
383
384
/**
385
 * Display the Quick Share box
386
 *
387
 */
388
function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
389
	if ( $shortlink_title == '' )
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
390
		$shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>';
391
	if ( $share_title == '' )
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
392
		$share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>';
393
394
	// Allow plugins to short-circuit the whole function
395
	$pre = yourls_apply_filter( 'shunt_share_box', false );
396
	if ( false !== $pre )
397
		return $pre;
398
399
    // Make sure IDN domains are in their UTF8 form
400
    $shorturl = yourls_normalize_uri($shorturl);
401
402
	$text   = ( $text ? '"'.$text.'" ' : '' );
403
	$title  = ( $title ? "$title " : '' );
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $title instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
404
	$share  = yourls_esc_textarea( $title.$text.$shorturl );
405
	$count  = 280 - strlen( $share );
406
	$hidden = ( $hidden ? 'style="display:none;"' : '' );
407
408
	// Allow plugins to filter all data
409
	$data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
410
	$data = yourls_apply_filter( 'share_box_data', $data );
411
	extract( $data );
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type null; however, parameter $var_array of extract() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

411
	extract( /** @scrutinizer ignore-type */ $data );
Loading history...
412
413
	$_share = rawurlencode( $share );
414
	$_url   = rawurlencode( $shorturl );
415
	?>
416
417
	<div id="shareboxes" <?php echo $hidden; ?>>
418
419
		<?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>
420
421
		<div id="copybox" class="share">
422
		<?php echo $shortlink_title; ?>
423
			<p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
424
			<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>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 167 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
425
			<?php if( yourls_do_log_redirect() ) { ?>
426
			<br/><small><?php yourls_e( 'Stats' ); ?>: <a id="statlink" href="<?php echo yourls_esc_url( $shorturl ); ?>+"><?php echo yourls_esc_url( $shorturl ); ?>+</a></small>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 169 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
427
			<input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" />
428
			<?php } ?>
429
			</p>
430
		</div>
431
432
		<?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>
433
434
		<div id="sharebox" class="share">
435
			<?php echo $share_title; ?>
436
			<div id="tweet">
437
				<span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>
438
				<textarea id="tweet_body"><?php echo $share; ?></textarea>
439
			</div>
440
			<p id="share_links"><?php yourls_e( 'Share with' ); ?>
441
				<a id="share_tw" href="https://twitter.com/intent/tweet?text=<?php echo $_share; ?>" title="<?php yourls_e( 'Tweet this!' ); ?>" onclick="share('tw');return false">Twitter</a>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 179 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
442
				<a id="share_fb" href="https://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e( 'Share on Facebook' ); ?>" onclick="share('fb');return false;">Facebook</a>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 184 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
443
				<?php
444
				yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );
445
				// Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.
446
				?>
447
			</p>
448
		</div>
449
450
		<?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>
451
452
	</div>
453
454
	<?php
455
}
456
457
/**
458
 * Die die die
459
 *
460
 */
461
function yourls_die( $message = '', $title = '', $header_code = 200 ) {
462 3
    yourls_do_action( 'pre_yourls_die', $message, $title, $header_code );
463
464
	yourls_status_header( $header_code );
465
466
	if( !yourls_did_action( 'html_head' ) ) {
467
		yourls_html_head();
468
		yourls_html_logo();
469
	}
470
	echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" );
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $title instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
471
	echo yourls_apply_filter( 'die_message', "<p>$message</p>" );
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $message instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
472
    // Hook into 'yourls_die' to add more elements or messages to that page
473
	yourls_do_action( 'yourls_die' );
474
	if( !yourls_did_action( 'html_footer' ) ) {
475
		yourls_html_footer(false);
476
	}
477
	die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
478
}
479
480
/**
481
 * Return an "Edit" row for the main table
482
 *
483
 * @param string $keyword Keyword to edit
484
 * @return string HTML of the edit row
485
 */
486
function yourls_table_edit_row( $keyword ) {
487
    $keyword = yourls_sanitize_keyword($keyword);
488
	$id = yourls_string2htmlid( $keyword ); // used as HTML #id
489
	$url = yourls_get_keyword_longurl( $keyword );
490
	$title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );
491
	$safe_url = yourls_esc_attr( $url );
492
	$safe_title = yourls_esc_attr( $title );
493
	$safe_keyword = yourls_esc_attr( $keyword );
494
495
    // Make strings sprintf() safe: '%' -> '%%'
496
    $safe_url = str_replace( '%', '%%', $safe_url );
497
    $safe_title = str_replace( '%', '%%', $safe_title );
498
499
	$www = yourls_link();
500
501
	$nonce = yourls_create_nonce( 'edit-save_'.$id );
502
503
	if( $url ) {
504
		$return = <<<RETURN
505
<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="$safe_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');" />&nbsp;<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="$safe_keyword"/><input type="hidden" id="nonce_$id" value="$nonce"/></td></tr>
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 888 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
506
RETURN;
507
		$return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 204 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
508
	} else {
509
		$return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
510
	}
511
512
	$return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );
513
514
	return $return;
515
}
516
517
/**
518
 * Return an "Add" row for the main table
519
 *
520
 * @return string HTML of the edit row
521
 */
522
function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) {
523 1
    $keyword  = yourls_sanitize_keyword($keyword);
524 1
	$id       = yourls_string2htmlid( $keyword ); // used as HTML #id
525 1
	$shorturl = yourls_link( $keyword );
526
527 1
	$statlink = yourls_statlink( $keyword );
528
529 1
	$delete_link = yourls_nonce_url( 'delete-link_'.$id,
530 1
		yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
531
	);
532
533 1
	$edit_link = yourls_nonce_url( 'edit-link_'.$id,
534 1
		yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
535
	);
536
537
	// Action link buttons: the array
538
	$actions = array(
539
		'stats' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
540 1
			'href'    => $statlink,
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 3 space(s) but found 4
Loading history...
541 1
			'id'      => "statlink-$id",
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 5 space(s) but found 6
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
542 1
			'title'   => yourls_esc_attr__( 'Stats' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 3
Loading history...
543 1
			'anchor'  => yourls__( 'Stats' ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 1 space(s) but found 2
Loading history...
544
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 13 space(s), but found 2.
Loading history...
545
		'share' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
546 1
			'href'    => '',
547 1
			'id'      => "share-button-$id",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
548 1
			'title'   => yourls_esc_attr__( 'Share' ),
549 1
			'anchor'  => yourls__( 'Share' ),
550 1
			'onclick' => "toggle_share('$id');return false;",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
551
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 13 space(s), but found 2.
Loading history...
552
		'edit' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 3 space(s) but found 1
Loading history...
553 1
			'href'    => $edit_link,
554 1
			'id'      => "edit-button-$id",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
555 1
			'title'   => yourls_esc_attr__( 'Edit' ),
556 1
			'anchor'  => yourls__( 'Edit' ),
557 1
			'onclick' => "edit_link_display('$id');return false;",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
558
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 12 space(s), but found 2.
Loading history...
559
		'delete' => array(
0 ignored issues
show
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
560 1
			'href'    => $delete_link,
561 1
			'id'      => "delete-button-$id",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
562 1
			'title'   => yourls_esc_attr__( 'Delete' ),
563 1
			'anchor'  => yourls__( 'Delete' ),
564 1
			'onclick' => "remove_link('$id');return false;",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
565
		)
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 14 space(s), but found 2.
Loading history...
566
	);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 12 space(s), but found 1.
Loading history...
567 1
	$actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword );
568
569
	// Action link buttons: the HTML
570 1
	$action_links = '';
571 1
	foreach( $actions as $key => $action ) {
572 1
		$onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;
0 ignored issues
show
Coding Style introduced by
Space found before semicolon; expected "'';" but found "'' ;"
Loading history...
573 1
		$action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',
574 1
			$action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 103 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
575
		);
576
	}
577 1
	$action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
578
579 1
	if( ! $title )
580
		$title = $url;
581
582 1
	$protocol_warning = '';
583 1
	if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) )
584
		$protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">&#9733;</span>' );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 160 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
585
586
	// Row cells: the array
587
	$cells = array(
588
		'keyword' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 3 space(s) but found 1
Loading history...
589 1
			'template'      => '<a href="%shorturl%">%keyword_html%</a>',
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 5 space(s) but found 6
Loading history...
590 1
			'shorturl'      => yourls_esc_url( $shorturl ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 5 space(s) but found 6
Loading history...
591 1
			'keyword_html'  => yourls_esc_html( $keyword ),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 1 space(s) but found 2
Loading history...
592
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 15 space(s), but found 2.
Loading history...
593
		'url' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 7 space(s) but found 1
Loading history...
594 1
			'template'      => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 152 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
595 1
			'long_url'      => yourls_esc_url( $url ),
596 1
			'title_attr'    => yourls_esc_attr( $title ),
597 1
			'title_html'    => yourls_esc_html( yourls_trim_long_string( $title ) ),
598 1
			'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ),
599 1
			'warning'       => $protocol_warning,
600
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 11 space(s), but found 2.
Loading history...
601
		'timestamp' => array(
602 1
			'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%',
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
603 1
            'timestamp' => $timestamp,
604 1
			'date'     => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )),
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 6 space(s) but found 5
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 113 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
605
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 17 space(s), but found 2.
Loading history...
606
		'ip' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 8 space(s) but found 1
Loading history...
607 1
			'template' => '%ip%',
608 1
			'ip'       => $ip,
609
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 10 space(s), but found 2.
Loading history...
610
		'clicks' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
611 1
			'template' => '%clicks%',
612 1
			'clicks'   => yourls_number_format_i18n( $clicks, 0, '', '' ),
0 ignored issues
show
Unused Code introduced by
The call to yourls_number_format_i18n() has too many arguments starting with ''. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

612
			'clicks'   => /** @scrutinizer ignore-call */ yourls_number_format_i18n( $clicks, 0, '', '' ),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
613
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 14 space(s), but found 2.
Loading history...
614
		'actions' => array(
0 ignored issues
show
Coding Style introduced by
Array double arrow not aligned correctly; expected 3 space(s) but found 1
Loading history...
615 1
			'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>',
616 1
			'actions'  => $action_links,
617 1
			'id'       => $id,
618 1
			'keyword'  => $keyword,
619
		),
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 15 space(s), but found 2.
Loading history...
620
	);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 10 space(s), but found 1.
Loading history...
621 1
	$cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 118 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
622
623
	// Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value.
624 1
	$row = "<tr id=\"id-$id\">";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
625 1
	foreach( $cells as $cell_id => $elements ) {
626 1
		$row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id );
627
		$row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 146 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
628 1
		$row .= '</td>';
629
	}
630 1
	$row .= "</tr>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal </tr> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
631 1
	$row  = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
632
633 1
	return $row;
634
}
635
636
/**
637
 * Echo the main table head
638
 *
639
 */
640
function yourls_table_head() {
641
	$start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 102 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
642
	echo yourls_apply_filter( 'table_head_start', $start );
643
644
	$cells = yourls_apply_filter( 'table_head_cells', array(
645
		'shorturl' => yourls__( 'Short URL' ),
646
		'longurl'  => yourls__( 'Original URL' ),
647
		'date'     => yourls__( 'Date' ),
648
		'ip'       => yourls__( 'IP' ),
649
		'clicks'   => yourls__( 'Clicks' ),
650
		'actions'  => yourls__( 'Actions' )
0 ignored issues
show
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
651
	) );
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 51 space(s), but found 1.
Loading history...
652
	foreach( $cells as $k => $v ) {
653
		echo "<th id='main_table_head_$k'>$v</th>\n";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $k instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $v instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
654
	}
655
656
	$end = "</tr></thead>\n";
657
	echo yourls_apply_filter( 'table_head_end', $end );
658
}
659
660
/**
661
 * Echo the tbody start tag
662
 *
663
 */
664
function yourls_table_tbody_start() {
665
	echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );
666
}
667
668
/**
669
 * Echo the tbody end tag
670
 *
671
 */
672
function yourls_table_tbody_end() {
673
	echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );
674
}
675
676
/**
677
 * Echo the table start tag
678
 *
679
 */
680
function yourls_table_end() {
681
	echo yourls_apply_filter( 'table_end', '</table></main>' );
682
}
683
684
/**
685
 * Echo HTML tag for a link
686
 *
687
 */
688
function yourls_html_link( $href, $title = '', $element = '' ) {
689
	if( !$title )
690
		$title = $href;
691
	if( $element )
692
		$element = sprintf( 'id="%s"', yourls_esc_attr( $element ) );
693
	$link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
694
	echo yourls_apply_filter( 'html_link', $link );
695
}
696
697
/**
698
 * Display the login screen. Nothing past this point.
699
 *
700
 */
701
function yourls_login_screen( $error_msg = '' ) {
702
	yourls_html_head( 'login' );
703
704
	$action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' );
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
705
706
	yourls_html_logo();
707
	?>
708
	<div id="login">
709
		<form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>
710
			<?php
711
				if( !empty( $error_msg ) ) {
0 ignored issues
show
Coding Style introduced by
First line of embedded PHP code must be indented 3 spaces; 4 found
Loading history...
712
					echo '<p class="error">'.$error_msg.'</p>';
713
				}
714
				yourls_do_action( 'login_form_top' );
715
			?>
716
			<p>
717
				<label for="username"><?php yourls_e( 'Username' ); ?></label><br />
718
				<input type="text" id="username" name="username" size="30" class="text" />
719
			</p>
720
			<p>
721
				<label for="password"><?php yourls_e( 'Password' ); ?></label><br />
722
				<input type="password" id="password" name="password" size="30" class="text" />
723
			</p>
724
			<?php
725
				yourls_do_action( 'login_form_bottom' );
0 ignored issues
show
Coding Style introduced by
First line of embedded PHP code must be indented 3 spaces; 4 found
Loading history...
726
			?>
727
			<p style="text-align: right;">
728
				<input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" />
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 106 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
729
			</p>
730
			<?php
731
				yourls_do_action( 'login_form_end' );
0 ignored issues
show
Coding Style introduced by
First line of embedded PHP code must be indented 3 spaces; 4 found
Loading history...
732
			?>
733
		</form>
734
		<script type="text/javascript">$('#username').focus();</script>
735
	</div>
736
	<?php
737
	yourls_html_footer();
738
	die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
739
}
740
741
/**
742
 * Display the admin menu
743
 *
744
 */
745
function yourls_html_menu() {
746
747
	// Build menu links
748 1
	if( defined( 'YOURLS_USER' ) ) {
749 1
		$logout_link = yourls_apply_filter( 'logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' (<a href="' . yourls_admin_url( 'index.php' ) . '?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 267 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
750
	} else {
751
		$logout_link = yourls_apply_filter( 'logout_link', '' );
752
	}
753 1
	$help_link   = yourls_apply_filter( 'help_link',   '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
754
755 1
	$admin_links    = array();
756 1
	$admin_sublinks = array();
757
758 1
	$admin_links['admin'] = array(
759 1
		'url'    => yourls_admin_url( 'index.php' ),
760 1
		'title'  => yourls__( 'Go to the admin interface' ),
761 1
		'anchor' => yourls__( 'Admin interface' )
0 ignored issues
show
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
762
	);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 25 space(s), but found 1.
Loading history...
763
764 1
	if( yourls_is_admin() ) {
765
		$admin_links['tools'] = array(
766
			'url'    => yourls_admin_url( 'tools.php' ),
767
			'anchor' => yourls__( 'Tools' )
0 ignored issues
show
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
768
		);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 26 space(s), but found 2.
Loading history...
769
		$admin_links['plugins'] = array(
770
			'url'    => yourls_admin_url( 'plugins.php' ),
771
			'anchor' => yourls__( 'Manage Plugins' )
0 ignored issues
show
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
772
		);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 28 space(s), but found 2.
Loading history...
773
		$admin_sublinks['plugins'] = yourls_list_plugin_admin_pages();
774
	}
775
776 1
	$admin_links    = yourls_apply_filter( 'admin_links',    $admin_links );
777 1
	$admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks );
778
779
	// Now output menu
780 1
	echo '<nav role="navigation"><ul id="admin_menu">'."\n";
781 1
	if ( yourls_is_private() && !empty( $logout_link ) )
782 1
		echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>';
783
784 1
	foreach( (array)$admin_links as $link => $ar ) {
785 1
		if( isset( $ar['url'] ) ) {
786 1
			$anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
787 1
			$title  = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
788 1
			printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
789
		}
790
		// Output submenu if any. TODO: clean up, too many code duplicated here
791 1
		if( isset( $admin_sublinks[$link] ) ) {
792
			echo "<ul>\n";
793
			foreach( $admin_sublinks[$link] as $link => $ar ) {
0 ignored issues
show
Comprehensibility Bug introduced by
$link is overwriting a variable from outer foreach loop.
Loading history...
Comprehensibility Bug introduced by
$ar is overwriting a variable from outer foreach loop.
Loading history...
794
				if( isset( $ar['url'] ) ) {
795
					$anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
796
					$title  = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
797
					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 );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 162 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
798
				}
799
			}
800
			echo "</ul>\n";
801
		}
802
	}
803
804 1
	if ( isset( $help_link ) )
805 1
		echo '<li id="admin_menu_help_link">' . $help_link .'</li>';
806
807 1
	yourls_do_action( 'admin_menu' );
808 1
	echo "</ul></nav>\n";
809 1
	yourls_do_action( 'admin_notices' );
810 1
	yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'
811
	/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Coding Style introduced by
Empty line required before block comment
Loading history...
812
	To display a notice:
0 ignored issues
show
Coding Style introduced by
First line of comment not aligned correctly; expected 5 spaces but found 1
Loading history...
813
	$message = "<div>OMG, dude, I mean!</div>" );
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 5 spaces but found 1
Loading history...
814
	yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } );
0 ignored issues
show
Coding Style introduced by
Comment line indented incorrectly; expected at least 5 spaces but found 1
Loading history...
815
	*/
0 ignored issues
show
Coding Style introduced by
Empty line required after block comment
Loading history...
816 1
}
817
818
/**
819
 * Wrapper function to display admin notices
820
 *
821
 */
822
function yourls_add_notice( $message, $style = 'notice' ) {
823
	// Escape single quotes in $message to avoid breaking the anonymous function
824 1
	$message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style );
825
	yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } );
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
826 1
}
827
828
/**
829
 * Return a formatted notice
830
 *
831
 */
832
function yourls_notice_box( $message, $style = 'notice' ) {
833
	return <<<HTML
834 1
	<div class="$style">
835 1
	<p>$message</p>
836
	</div>
837
HTML;
838
}
839
840
/**
841
 *  Display a page
842
 *
843
 *  Includes content of a PHP file from the YOURLS_PAGEDIR directory, as if it
844
 *  were a standard short URL (ie http://sho.rt/$page)
845
 *
846
 *  @since 1.0
847
 *  @param $page      PHP file to display
848
 */
849
function yourls_page( $page ) {
850
    if( !yourls_is_page($page)) {
851
		yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 );
852
    }
853
854
	yourls_do_action( 'pre_page', $page );
855
	include_once( YOURLS_PAGEDIR . "/$page.php" );
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
856
	yourls_do_action( 'post_page', $page );
857
}
858
859
/**
860
 * Display the language attributes for the HTML tag.
861
 *
862
 * Builds up a set of html attributes containing the text direction and language
863
 * information for the page. Stolen from WP.
864
 *
865
 * @since 1.6
866
 */
867
function yourls_html_language_attributes() {
868 1
	$attributes = array();
869 1
	$output = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $output is dead and can be removed.
Loading history...
870
871 1
	$attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' );
872
873 1
	$doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' );
874
	// Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR
875 1
	if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) {
0 ignored issues
show
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
876 1
		if( $doctype == 'xhtml' ) {
0 ignored issues
show
Coding Style introduced by
Operator == prohibited; use === instead
Loading history...
877
			$attributes[] = "xml:lang=\"$lang\"";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $lang instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
878
		} else {
879 1
			$attributes[] = "lang=\"$lang\"";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $lang instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
880
		}
881
	}
882
883 1
	$output = implode( ' ', $attributes );
884 1
	$output = yourls_apply_filter( 'html_language_attributes', $output );
885 1
	echo $output;
886 1
}
887
888
/**
889
 * Output translated strings used by the Javascript calendar
890
 *
891
 * @since 1.6
892
 */
893
function yourls_l10n_calendar_strings() {
894
	echo "\n<script>\n";
895
	echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal var l10n_cal_month = does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
896
	echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal var l10n_cal_days = does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
897
	echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal var l10n_cal_today = \" does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
898
	echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal var l10n_cal_close = \" does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
899
	echo "</script>\n";
900
901
	// Dummy returns, to initialize l10n strings used in the calendar
902
	yourls__( 'Today' );
903
	yourls__( 'Close' );
904
}
905
906
907
/**
908
 * Display a notice if there is a newer version of YOURLS available
909
 *
910
 * @since 1.7
911
 */
912
function yourls_new_core_version_notice() {
913
914
	$checks = yourls_get_option( 'core_version_checks' );
915
    $latest = isset($checks->last_result->latest) ? yourls_sanitize_version($checks->last_result->latest) : false;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 114 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
916
917
	if( $latest AND version_compare( $latest, YOURLS_VERSION, '>' ) ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
918
		$msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest );
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 126 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
919
		yourls_add_notice( $msg );
920
	}
921
}
922
923
/**
924
 * Get search text from query string variables search_protocol, search_slashes and search
925
 *
926
 * Some servers don't like query strings containing "(ht|f)tp(s)://". A javascript bit
927
 * explodes the search text into protocol, slashes and the rest (see JS function
928
 * split_search_text_before_search()) and this function glues pieces back together
929
 * See issue https://github.com/YOURLS/YOURLS/issues/1576
930
 *
931
 * @since 1.7
932
 * @return string Search string
933
 */
934
function yourls_get_search_text() {
935
	$search = '';
936
	if( isset( $_GET['search_protocol'] ) )
937
		$search .= $_GET['search_protocol'];
938
	if( isset( $_GET['search_slashes'] ) )
939
		$search .= $_GET['search_slashes'];
940
	if( isset( $_GET['search'] ) )
941
		$search .= $_GET['search'];
942
943
	return htmlspecialchars( trim( $search ) );
944
}
945
946
/**
947
 * Display or return HTML for a bookmarklet link
948
 *
949
 * @since 1.7.1
950
 * @param string $href    bookmarklet link (presumably minified code with "javascript:" scheme)
951
 * @param string $anchor  link anchor
952
 * @param bool   $echo    true to display, false to return the HTML
953
 * @return string         the HTML for a bookmarklet link
954
 */
955
function yourls_bookmarklet_link( $href, $anchor, $echo = true ) {
956
    $alert = yourls_esc_attr__( 'Drag to your toolbar!' );
957
    $link = <<<LINK
958
    <a href="$href" class="bookmarklet" onclick="alert('$alert');return false;">$anchor</a>
959
LINK;
960
961
    if( $echo )
962
        echo $link;
963
    return $link;
964
}
965
966
/**
967
 * Set HTML context (stats, index, infos, ...)
968
 *
969
 * @since  1.7.3
970
 * @param  string  $context
971
 * @return void
972
 */
973
function yourls_set_html_context($context) {
974 1
    yourls_get_db()->set_html_context($context);
975 1
}
976
977
/**
978
 * Get HTML context (stats, index, infos, ...)
979
 *
980
 * @since  1.7.3
981
 * @return string
982
 */
983
function yourls_get_html_context() {
984 1
    yourls_get_db()->get_html_context();
985
}
986