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