Issues (2756)

admin/install.php (8 issues)

1
<?php
2
define( 'YOURLS_ADMIN', true );
3
define( 'YOURLS_INSTALLING', true );
4
require_once( dirname( __DIR__ ).'/includes/load-yourls.php' );
5
require_once( YOURLS_INC.'/functions-install.php' );
6
7
$error   = array();
8
$warning = array();
9
$success = array();
10
11
// Check pre-requisites
12
if ( !yourls_check_PDO() ) {
13
	$error[] = yourls__( 'PHP extension for PDO not found' );
14
	yourls_debug_log( 'PHP PDO extension not found' );
15
}
16
17
if ( !yourls_check_database_version() ) {
18
	$error[] = yourls_s( '%s version is too old. Ask your server admin for an upgrade.', 'MySQL' );
19
	yourls_debug_log( 'MySQL version: ' . yourls_get_database_version() );
20
}
21
22
if ( !yourls_check_php_version() ) {
23
	$error[] = yourls_s( '%s version is too old. Ask your server admin for an upgrade.', 'PHP' );
24
	yourls_debug_log( 'PHP version: ' . PHP_VERSION );
25
}
26
27
// Is YOURLS already installed ?
28
if ( yourls_is_installed() ) {
29
	$error[] = yourls__( 'YOURLS already installed.' );
30
	// check if .htaccess exists, recreate otherwise. No error checking.
31
	if( !file_exists( YOURLS_ABSPATH.'/.htaccess' ) ) {
32
		yourls_create_htaccess();
33
	}
34
}
35
36
// Start install if possible and needed
37
if ( isset($_REQUEST['install']) && count( $error ) == 0 ) {
0 ignored issues
show
Operator == prohibited; use === instead
Loading history...
38
	// Create/update .htaccess file
39
	if ( yourls_create_htaccess() ) {
40
		$success[] = yourls__( 'File <tt>.htaccess</tt> successfully created/updated.' );
41
	} else {
42
		$warning[] = yourls__( 'Could not write file <tt>.htaccess</tt> in YOURLS root directory. You will have to do it manually. See <a href="http://yourls.org/htaccess">how</a>.' );
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 178 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...
43
	}
44
45
	// Create SQL tables
46
	$install = yourls_create_sql_tables();
47
	if ( isset( $install['error'] ) )
48
		$error = array_merge( $error, $install['error'] );
49
	if ( isset( $install['success'] ) )
50
		$success = array_merge( $success, $install['success'] );
51
}
52
53
54
// Start output
55
yourls_html_head( 'install', yourls__( 'Install YOURLS' ) );
56
?>
57
<div id="login">
58
	<form method="post" action="?"><?php // reset any QUERY parameters ?>
59
		<p>
60
			<img src="<?php yourls_site_url(); ?>/images/yourls-logo.svg" id="yourls-logo" alt="YOURLS" title="YOURLS" />
61
		</p>
62
		<?php
63
			// Print errors, warnings and success messages
0 ignored issues
show
First line of embedded PHP code must be indented 2 spaces; 3 found
Loading history...
64
			foreach ( array ('error', 'warning', 'success') as $info ) {
0 ignored issues
show
There must be no space between the "array" keyword and the opening parenthesis
Loading history...
65
				if ( count( $$info ) > 0 ) {
66
					echo "<ul class='$info'>";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $info 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...
67
					foreach( $$info as $msg ) {
68
						echo '<li>'.$msg."</li>\n";
69
					}
70
					echo '</ul>';
71
				}
72
			}
73
74
			// Display install button or link to admin area if applicable
75
			if( !yourls_is_installed() && !isset($_REQUEST['install']) ) {
76
				echo '<p style="text-align: center;"><input type="submit" name="install" value="' . yourls__( 'Install YOURLS') .'" class="button" /></p>';
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 143 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...
77
			} else {
78
				if( count($error) == 0 )
0 ignored issues
show
Operator == prohibited; use === instead
Loading history...
79
					echo '<p style="text-align: center;">&raquo; <a href="'.yourls_admin_url().'" title="' . yourls__( 'YOURLS Administration Page') . '">' . yourls__( 'YOURLS Administration Page') . '</a></p>';
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 196 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...
80
			}
81
		?>
82
	</form>
83
</div>
84
<?php yourls_html_footer(); ?>
85