]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/install.php
Use __DIR__ instead of dirname(__FILE__)
[Github/YOURLS.git] / admin / install.php
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_database_version() ) {
13         $error[] = yourls_s( '%s version is too old. Ask your server admin for an upgrade.', 'MySQL' );
14         yourls_debug_log( 'MySQL version: ' . yourls_get_database_version() );
15 }
16
17 if ( !yourls_check_php_version() ) {
18         $error[] = yourls_s( '%s version is too old. Ask your server admin for an upgrade.', 'PHP' );
19         yourls_debug_log( 'PHP version: ' . phpversion() );
20 }
21
22 // Is YOURLS already installed ?
23 if ( yourls_is_installed() ) {
24         $error[] = yourls__( 'YOURLS already installed.' );
25         // check if .htaccess exists, recreate otherwise. No error checking.
26         if( !file_exists( YOURLS_ABSPATH.'/.htaccess' ) ) {
27                 yourls_create_htaccess();
28         }
29 }
30
31 // Start install if possible and needed
32 if ( isset($_REQUEST['install']) && count( $error ) == 0 ) {
33         // Create/update .htaccess file
34         if ( yourls_create_htaccess() ) {
35                 $success[] = yourls__( 'File <tt>.htaccess</tt> successfully created/updated.' );
36         } else {
37                 $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>.' );
38         }
39
40         // Create SQL tables
41         $install = yourls_create_sql_tables();
42         if ( isset( $install['error'] ) )
43                 $error = array_merge( $error, $install['error'] );
44         if ( isset( $install['success'] ) )
45                 $success = array_merge( $success, $install['success'] );
46 }
47
48
49 // Start output
50 yourls_html_head( 'install', yourls__( 'Install YOURLS' ) );
51 ?>
52 <div id="login">
53         <form method="post" action="?"><?php // reset any QUERY parameters ?>
54                 <p>
55                         <img src="<?php yourls_site_url(); ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" />
56                 </p>
57                 <?php
58                         // Print errors, warnings and success messages
59                         foreach ( array ('error', 'warning', 'success') as $info ) {
60                                 if ( count( $$info ) > 0 ) {
61                                         echo "<ul class='$info'>";
62                                         foreach( $$info as $msg ) {
63                                                 echo '<li>'.$msg."</li>\n";
64                                         }
65                                         echo '</ul>';
66                                 }
67                         }
68
69                         // Display install button or link to admin area if applicable
70                         if( !yourls_is_installed() && !isset($_REQUEST['install']) ) {
71                                 echo '<p style="text-align: center;"><input type="submit" name="install" value="' . yourls__( 'Install YOURLS') .'" class="button" /></p>';
72                         } else {
73                                 if( count($error) == 0 )
74                                         echo '<p style="text-align: center;">&raquo; <a href="'.yourls_admin_url().'" title="' . yourls__( 'YOURLS Administration Page') . '">' . yourls__( 'YOURLS Administration Page') . '</a></p>';
75                         }
76                 ?>
77         </form>
78 </div>
79 <?php yourls_html_footer(); ?>